Show all threads Hide all threads Show all messages Hide all messages | Page 1 | I don't know K's mean. | Fudong | 1009. K-based Numbers | 15 Aug 2003 11:25 | 1 | | Filippov Nickolas SSAU#2's AC program is HERE! | Nickolas | 1009. K-based Numbers | 13 Dec 2007 20:26 | 6 | program kbasednumbers; var i:integer; a:array[0..16] of longint; n,k:word; begin read(n); read(k); a[0]:=1; a[1]:=k-1; for i:=2 to n do a[i]:=(k-1)*(a[i-1]+a[i-2]); writeln(a[n]); end. var n,k,i :byte; p1,p2,p3 :longint; begin read(n,k); p2:=1; p1:=k; for i:=1 to n-2 do begin p3:=p1; p1:=(k-1)*(p1+p2); p2:=p3; end; writeln((k-1)*p1); end. Aidin_n7@hotmail.com i really can't understand the meaning of the problem. please help me Let's consider: f(n, 0) - an amount of valid n digits , k-based number. f(n, 0) - an amount of valid n digits, k-based number which ends with 0. f(n, 1) - an amount of valid n digits, k- based number which ends with 1,2,..,k - 1. We have: f(n, 1) = (k - 1)f(n - 1) f(n, 0) = f(n - 1, 1) = (k - 1)f(n -2) So, f(n) = f(n, 1) + f(n, 0) = (k -1)( f(n - 1) + f(n - 2)) Edited by author 20.12.2005 17:39 I get AC f(t)=f(t-1)*(k-1)+f(t-2)*(k-1); thanks Let's consider: f(n, 0) - an amount of valid n digits , k-based number. f(n, 0) - an amount of valid n digits, k-based number which ends with 0. f(n, 1) - an amount of valid n digits, k- based number which ends with 1,2,..,k - 1. We have: f(n, 1) = (k - 1)f(n - 1) f(n, 0) = f(n - 1, 1) = (k - 1)f(n -2) So, f(n) = f(n, 1) + f(n, 0) = (k -1)( f(n - 1) + f(n - 2)) Edited by author 20.12.2005 17:39 It's so simple! And I'm so stupid, that didn't guess it myself. :( | CA means CE :) | faust | 1009. K-based Numbers | 28 Jan 2003 12:55 | 1 | | Why CA???? | faust | 1009. K-based Numbers | 28 Jan 2003 12:51 | 1 | #include <iostream.h> long int F0[1800], F1[1800]; int main(void) { clrscr(); int N, K; cin >> N >> K; F0[1] = 1; F1[1] = K - 1; F0[2] = F1[1]; F1[2] = (K - 1) * F1[1]; for(int i = 3 ; i <= N ; ++i) { F0[i] = F1[i - 1]; F1[i] = (K - 1) * (F0[i - 1] + F1[i - 1]); }; cout << F0[N] + F1[N]; return 0; }; thanks :) | Why I got WA? Can you help me? | Happybird | 1009. K-based Numbers | 10 Jan 2003 09:11 | 3 | program my1009(input,output); const Max=2000; type myrecord=array[1..Max] of longint; var N,K:byte; total:real; save:array[1..2] of myrecord; temp:myrecord; Mark:array[1..2] of longint; procedure work; var work_i,work_j:byte; begin save[1,1]:=(k-1); mark[1]:=1;mark[2]:=0; for work_i:=2 to N do begin temp:=save[1]; for work_j:=1 to mark[2] do save[1,work_j]:=save[2,work_j]*(k-1); for work_j:=1 to mark[1] do save[2,work_j]:=temp[work_j]; Mark[1]:=Mark[1]+Mark[2]; for work_j:=Mark[2]+1 to Mark[1] do save[1,work_j]:=temp[work_j-mark[2]]*(k-1); Mark[2]:=Mark[1]-Mark[2]; end; total:=0; for work_i:=1 to mark[2] do total:=total+save[2,work_i]; for work_i:=1 to mark[1] do total:=total+save[1,work_i]; writeln(total:1:0); end; begin read(n,k); work; end. I write it for 1013, so I use the Big Integers class. but actually they are the same problem except for the Scale. #include <iostream> #include <cstring> using namespace std; //////////////////////////////////////////////////////////////// // this class is not efficient enough, but it's useful! // BigNum class BigNum { friend ostream& operator<<(ostream &out, const BigNum &rhs); friend const BigNum operator+(const BigNum &lhs, const BigNum &rhs); friend const BigNum operator*(const BigNum &lhs, int digit); public: BigNum(); BigNum(int digit); BigNum& operator=(int digit); BigNum& operator+=(const BigNum &rhs); BigNum& operator*=(int digit); private: static const int MAX_D = 500; int numbers[MAX_D]; }; const int BigNum::MAX_D; BigNum::BigNum() { memset(numbers, 0, sizeof(numbers)); } BigNum::BigNum(int digit) { memset(numbers, 0, sizeof(numbers)); int carry = digit; for (int i = 0; i < MAX_D && carry != 0; ++i) { numbers[i] = carry % 10000; carry /= 10000; } } BigNum& BigNum::operator=(int digit) { int carry = digit; for (int i = 0; i < MAX_D && carry != 0; ++i) { numbers[i] = carry % 10000; carry /= 10000; } return (*this); } BigNum& BigNum::operator+=(const BigNum &rhs) { int carry = 0; for (int i = 0; i < MAX_D; ++i) { carry += (numbers[i] + rhs.numbers[i]); numbers[i] = carry % 10000; carry /= 10000; } return (*this); } BigNum& BigNum::operator*=(int digit) { int carry = 0; for (int i = 0; i < MAX_D; ++i) { carry += (numbers[i] * digit); numbers[i] = carry % 10000; carry /= 10000; } return (*this); } ostream& operator<<(ostream &out, const BigNum &rhs) { int idx = BigNum::MAX_D - 1; for ( ; (idx >= 0) && (rhs.numbers[idx] == 0); --idx) ; if (idx < 0) { return (out << 0); } cout << rhs.numbers[idx--]; for ( ; idx >= 0; --idx) { if (rhs.numbers[idx] / 10 == 0) cout << "000"; else if (rhs.numbers[idx] / 100 == 0) cout << "00"; else if (rhs.numbers[idx] / 1000 == 0) cout << "0"; out << rhs.numbers[idx]; } return out; } const BigNum operator+(const BigNum &lhs, const BigNum &rhs) { return BigNum(lhs) += rhs; } const BigNum operator*(const BigNum &lhs, int digit) { return BigNum(lhs) *= digit; } const BigNum operator*(int digit, const BigNum &rhs) { return BigNum(rhs) *= digit; } ////////////////////////////////////////////////////////////////////// //// const int MAX_N = 1800; const int MAX_K = 10; int N, K; int main() { cin >> N >> K; BigNum Fn1 = 1, Fn2 = K-1, Fn; BigNum *pfn1 = &Fn1, *pfn2 = &Fn2, *pfn = &Fn; for (int i = 2; i <= N; ++i) { *pfn = (K-1) * (*pfn1 + *pfn2); pfn1 = pfn2; pfn2 = pfn; pfn = pfn1; } cout << (*pfn2) << endl; // return 0; }
var n,k,i :byte; p1,p2,p3 :longint; begin read(n,k); p2:=1; p1:=k; for i:=1 to n-2 do begin p3:=p1; p1:=(k-1)*(p1+p2); p2:=p3; end; writeln((k-1)*p1); end. ~~~~~~~~~~~~~ wish it help you Yours Aidin_n7 (happybird is nice name!) | I know the recursive , but my prog give WA here . please help me | Accepted | 1009. K-based Numbers | 2 Dec 2002 21:46 | 1 | i know the recursive relation . F[l] := (k-1)(F[l-1] + F[l-2]) F[n] := (k-1)(F[n-1]) but my prog give WA here . i don know why . help me please. here is my prog : #include <stdio.h> int n,k,z,lb,a[36],b[36]; void jam() { int temp[36]; int i; for (i=0;i<=lb;i++) temp[i] = b[i]; for (i=0;i<=lb;i++) { b[i] = a[i] + b[i]; if (b[i] > 9) { b[i] = b[i] - 10; b[i+1] = b[i+1] + 1; } } for (i=0;i<=lb;i++) a[i] = temp[i]; if (b[lb+1] > 0) lb++; } void zarb() { int j; for (j = 0 ;j <= lb ; j ++) { b[j] = b[j] * (k-1); if (b[j] > 9) { b[j] = b[j]/10; b[j+1] = b[j+1] + b[j]%10; } } if (b[lb+1] > 0) lb++; } void main(void) { scanf ("%d\n%d",&n,&k); a[0] = 0; b[0] = k; lb = 0; if (b[0] = 10) { b[0] = 0; b[1] = 1; lb = 1; } for (z=1;z<n-1;z++) { jam(); zarb(); } for (z=0;z<=lb;z++) { b[z] = b[z] * (k-1); if (b[z] > 9) { b[z+1] = b[z]/10; b[z] = b[z]%10; } } if (b[lb+1] > 0) lb++; for (z=lb;z>=0;z--) printf ("%d",b[z]); } | what's output for N=8 , K=10 ??? | ss | 1009. K-based Numbers | 5 Apr 2009 13:51 | 7 | > > I think it's 85096170 i've just got accpted thankz | A right answer | VladG | 1009. K-based Numbers | 25 Apr 2003 20:28 | 4 | I didn't found how to evaluate the result exactly with a close expression, but I just count all the results with loops and a recursion. For some of an input data it took more than 2 secs., therefore I ran my program in offline for all possible input values. (Thanks that there were not so many.) The program running took a couple of minutes, then I collected all the found results as an array and submitted the program that just looked for the appropriate entry in the array and returned the right answer!!! | Why wrong answer ? | svg | 1009. K-based Numbers | 25 Apr 2003 20:35 | 2 | In forum I saw this ( http://acm.timus.ru/messages.asp?id=3516):== cut == Use DP: M[1] = K; M[2] = (K-1) * K; M[K] = (K-1) * ( Mas[K-2] + Mas[K-1] ); k<N; Answer is M[N] = (K-1)*Mas[N-1] == cut == And author this message solve the problem But for N = 3 and K = 10 M[1] = 10, M[2] = 90 M[3] = 9 * 90 = 810 But that wrong, because for N = 3 we have Kxx numbers, where K=1..9, xx - can't be 00, so 99 variants and answer is 9 * 99 = 891 The correct dp fomula should be: M[1] = K-1; M[2] = (K-1) * K; M[K] = (K-1) * ( Mas[K-2] + Mas[K-1] ); k<=N; Answer is M[N] so for your case,m[1]=9;m[2]=90;m[3]=9*(9+90)=891. | What's NA!!!!!!!!!!!!!!!!!!!!!!!! | wlhman | 1009. K-based Numbers | 26 Sep 2002 05:32 | 1 | | WHY ACCESS_VIOLATION??? | purplefish | 1009. K-based Numbers | 30 May 2002 23:00 | 2 | #include <iostream> using namespace std; void addNumber (int, int, int*); bool searchNumber (int, int*); void main(){ int digit = 0, base = 2; int i = 0, j = 0, min = 1, max = 1, answer = 0; int number[16] = {0}; cin >> digit >> base; number[digit-1] = 1;
for (i = 1; i <= digit; i++){ max *= base; }
min = (max/base); for (j = min; j <= max; j++){
addNumber(0, base, number);
if (searchNumber(digit, number)){ answer++; }; } cout << answer; } void addNumber (int i, int base, int* number){
if ((number[i] + 1) < base){ number[i]++; } else { number[i] = 0; i++; addNumber(i, base, number); } }; bool searchNumber (int digit, int* number){
for (int i = 0; i < (digit-1); i++){ if (number[i] == 0){ if (number[i+1] == 0){ return false; } } } return true; } | whi my program get CE? ENIBODY CAN HELP MEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE | I am david. Tabo. | 1009. K-based Numbers | 13 Apr 2002 05:03 | 2 | var ric,min,max,i,j,k,l,m,n: longint; a:array [1..1000] of longint; begin readln (n,k); min:=1; i:=1; while i=n-1 do begin min:=min*10; inc (i); end; max:=k-1; j:=1; while j=n-1 do begin max:=max*10+(k-1); inc (j); end; for i:=min to max do begin ric:=i; l:=0; while ric<>0 do begin inc (l); a[l]:=(ric mod 10); ric:=(ric div 10); end; for j:=1 to l do if a[j]>k-1 then begin a[j]:=0; inc (a[j+1]); end; i:=0; for j:=l downto 1 do i:=i*10+a[j]; if (i mod 100)<>0 then inc(m); end; writeln (m); end. > var ric,min,max,i,j,k,l,m,n: longint; > a:array [1..1000] of longint; > begin > readln (n,k); > min:=1; > i:=1; > while i=n-1 do > begin > min:=min*10; > inc (i); > end; > max:=k-1; > j:=1; > while j=n-1 do > begin > max:=max*10+(k-1); > inc (j); > end; > for i:=min to max do > begin > ric:=i; > l:=0; > while ric<>0 do > begin > inc (l); > a[l]:=(ric mod 10); > ric:=(ric div 10); > end; > for j:=1 to l do > if a[j]>k-1 then > begin > a[j]:=0; > inc (a[j+1]); > end; > i:=0; {HAve a look at my comment - here is your wrong!!!} > for j:=l downto 1 do > i:=i*10+a[j]; > if (i mod 100)<>0 then > inc(m); > end; > writeln (m); > end. > Hei, the compiler in timus is Delphi - you can not change the value of a variable, that controls the cicle, but in PAscal that i spossible Where you have written "i=0", use another variable..I think, you will get accepted. Bye! from Vlado | Why my programm does not work? Help, me please. | Misha_W | 1009. K-based Numbers | 5 Mar 2002 00:29 | 1 | var n,k,i:byte;s:longint; function step(x,y:byte):longint; var i:byte;s:longint; begin s:=1; For i:=1 to y do s:=s*x; step:=s; end; function f(x:byte):longint; var i:byte;s:longint; begin s:=1; for i:=2 to x do s:=s*i; f:=s; end; Function c(n,k:byte):longint; begin c:=f(n) div f(k) div f(n-k); end; begin s:=0; readln(n); readln(k); n:=n-1; for i:=0 to round(n/2) do s:=s+c(n+1-i,i)*step(k-1,n-i); writeln(s*(k-1)); end. | Wrong Answer Again and Again | Jordan | 1009. K-based Numbers | 29 Aug 2011 01:25 | 4 | Sos!I really don't know why i always get this reply!Could anybody point out my fault or give me some testdata?Thanks > Sos!I really don't know why i always get this reply!Could anybody > point out my fault or give me some testdata?Thanks Use DP: M[1] = K; M[2] = (K-1) * K; M[K] = (K-1) * ( Mas[K-2] + Mas[K-1] ); k<N; Answer is M[N] = (K-1)*Mas[N-1]
so, A(i)=is the number of valid numbers where the I-th digit is 0 and,B(i)=is the number of valid numbers where the I-th digit is IN [1..9] program timus1009; const maxn=20; type ta=array[0..maxn]of integer; var n,k:integer; A,B:ta; i:integer; begin while not seekeof do begin readln(n); readln(k); A[1]:=0; B[1]:=k-1; for i:=2 to n do begin A[i]:=B[i-1]; B[i]:=(k-1)*(A[i-1]+B[i-1]); end; writeln(A[n]+B[n]); end; end. :) this is the same thing :) if you replace A[i-1] = B[i-2] you will get B[i] = (k - 1) * (B[i - 2] + B[i - 1]) | Why did my program compile error? | lyj_george | 1009. K-based Numbers | 6 Feb 2002 08:59 | 3 | In this program n is k , k is n var l : array [1..1000] of byte; n , k , ss : integer; tot : longint; function cf(aa,bb:integer) : longint; var temp , ii : longint; begin temp := 1; for ii := 1 to bb do temp := temp * aa; cf := temp; end; procedure try(now,left,source : integer); var jj : byte; begin if left = 0 then begin tot := tot + cf(n-1,k-source); exit; end; if now > k then exit; if left > k - now+1 then exit; for jj := 0 to 1 do if (jj = 0) or ((jj=1) and (l[now-1]<>1)) then begin l[now] := jj; try(now+1 , left-jj , source); end; end; begin readln(k); readln(n); tot := cf(n-1,k); for ss := 1 to k-1 do try(2,ss,ss); writeln(tot); end. > In this program n is k , k is n > var > l : array [1..1000] of byte; > n , k , ss : integer; > tot : longint; > function cf(aa,bb:integer) : longint; > var > temp , ii : longint; > begin > temp := 1; > for ii := 1 to bb do > temp := temp * aa; > cf := temp; > end; > procedure try(now,left,source : integer); > var > jj : byte; > begin > if left = 0 then begin > tot := tot + cf(n-1,k-source); > exit; > end; > if now > k then exit; > if left > k - now+1 then exit; > for jj := 0 to 1 do > if (jj = 0) or ((jj=1) and (l[now-1]<>1)) then begin > l[now] := jj; > try(now+1 , left-jj , source); > end; > end; > > begin > readln(k); > readln(n); > tot := cf(n-1,k); > for ss := 1 to k-1 do > try(2,ss,ss); > writeln(tot); > end. > 1. warning: missing program header; With header my GPC compiled your program? but ... 2. While trying to solve this problem and checking my e-mail i find one error: function or procedure can't use name 'try'. When i change 'try' in your program to 'trye', your program solve the problem. Thank you for your code :-) I've known that procedure or function name can't use "try".Thank you for your help. | Why my program does not work? | I am david. Tabo. | 1009. K-based Numbers | 4 Feb 2002 18:34 | 2 | >Why my program get Compilation error? >var ric,min,max,i,j,k,l,m,n: longint; > a:array [1..1000] of longint; >begin > read (n,k); > min:=1; > for i:=1 to n-1 do > min:=min*10; > max:=k-1; > for i:=1 to n-1 do > max:=max*10+(k-1); > for i:=min to max do > begin > ric:=i; > l:=0; > while ric<>0 do > begin > inc (l); > a[l]:=(ric mod 10); > ric:=(ric div 10); > end; > for j:=1 to l do > if a[j]>k-1 then > begin > a[j]:=0; > inc (a[j+1]); > end; > i:=0; > for j:=l downto 1 do > i:=i*10+a[j]; > if (i mod 100)<>0 then > inc(m); > end; > writeln (m); >end. > >Why my program get Compilation error? > >var ric,min,max,i,j,k,l,m,n: longint; > > a:array [1..1000] of longint; > >begin > > read (n,k); > > min:=1; > > for i:=1 to n-1 do > > min:=min*10; > > max:=k-1; > > for i:=1 to n-1 do > > max:=max*10+(k-1); > > for i:=min to max do > > begin > > ric:=i; > > l:=0; > > while ric<>0 do > > begin > > inc (l); > > a[l]:=(ric mod 10); > > ric:=(ric div 10); > > end; > > for j:=1 to l do > > if a[j]>k-1 then > > begin > > a[j]:=0; > > inc (a[j+1]); > > end; > > i:=0; > > for j:=l downto 1 do > > i:=i*10+a[j]; > > if (i mod 100)<>0 then > > inc(m); > > end; > > writeln (m); > >end. > 1. warning: missing program header; (program my1009) GPC have not find anu other errors ... 2. You change i into for. That's all. By ... Time Limit Exesteeded. | Who can tell me what means is "K-based"?And please give me an example.Thanks | qwt | 1009. K-based Numbers | 22 Jan 2002 10:38 | 4 | K-based. A number in Base k, a number is in Base K if all his digits are from 0 to K-1 (10-Based numbers are numbers used by people). The value is obtained as this: an*k**n + ... a0*k**0, where an through a0 are the digits from left to right order and k** is the power operation. Though is basic for you to know this concepts :) > K-based. A number in Base k, a number is in Base K if all his digits > are from 0 to K-1 (10-Based numbers are numbers used by people). The > value is obtained as this: > an*k**n + ... a0*k**0, where an through a0 are the digits from left > to right order and k** is the power operation. > Though is basic for you to know this concepts :) Hello Miguel Angel. Help me please. I think that for n=5 with every base there are 8 invalid numbers, aren't they. and for n=12 invalid numbers=1815 Unfortunately isn't right. A hint: Let n the amount of digits, and k the base for 1 digit you have from 1 to k valid numbers. for 2 digits you have from 1 to k and from 0 to k, so (k-1)k. You may do first "Binary Lexicographic Sequence" problem to have a notion of this :) | Thank you,I've done this problem already,and version II and III as well. | Huang Yizheng | 1009. K-based Numbers | 2 Nov 2001 14:17 | 2 | Yes, may email: raynaldo_adp@yahoo.com | What doesn't the problem mean?What number is called "valid"?What is "doesn't contain two successful zeros"?Can anybody give me an example? | Huang Yizheng | 1009. K-based Numbers | 27 Feb 2009 03:27 | 11 | yaeh... 100 - is valid in 10-digit system 55400342 - is valid in 5-digit system... > yaeh... > 100 - is valid in 10-digit system > 55400342 - is valid in 5-digit system... > > > > yaeh... > > 100 - is valid in 10-digit system > > 55400342 - is valid in 5-digit system... > > > > °ўИш > So, two successful zeros is zero, and after it another one zero, example: 1001123. There can't be leader zeros, such as 0123; 0123 - is 3- digits number. > > So, two successful zeros is zero, and after it another > one zero, example: 1001123. > There can't be leader zeros, such as 0123; 0123 - is 3- > digits number. Does the word "successful" means "consecutive" or "continuous"?Does it mean that the valid number mustn't contain two and more than two consecutive zeros (certainly not in the head)? For example,101010 is valid,but 101100 and 111000 is not valid,right? > > > So, two successful zeros is zero, and after it another > > one zero, example: 1001123. > > There can't be leader zeros, such as 0123; 0123 - is 3- > > digits number. > Does the word "successful" means "consecutive" > or "continuous"?Does it mean that the valid number mustn't > contain two and more than two consecutive zeros (certainly > not in the head)? > For example,101010 is valid,but 101100 and 111000 is not > valid,right? You are certainly right. Pay attention on the task's condition! in my oppinion the author mistakook successful with successive Edited by author 27.02.2009 02:14 Edited by author 27.02.2009 02:14 | I've got wrong answer. | haha 4444 | 1009. K-based Numbers | 4 Feb 2002 18:40 | 2 | I wanna know why i've got wrong answer, anybody help me please. > I wanna know why i've got wrong answer, anybody help me > please. > Try this test |
|
|