Is it 6 for all where n=1 and a,b>0? Because my AC solution gives 9 (yes, I implement idea from forum). For test 1 10 10 my solution gives 121 0 x y xx yy xy Edited by author 26.05.2020 00:20 Edited by author 26.05.2020 00:20 can't pass TEST#7, just can't,,,, test: 20 15 15 :) Answer is 10549134770590785600 ;-) Use QWORD instead of INT64! Thank you.I've got ac now. Thank you. Changed from signed int64 to unsigned int64 for c++. 1) Let's imagine, that there are n boxes and 1 another box with extra balles, which you didn't place in the first n. So, in fact you have n+1 boxes. 2) We can count the ways of putting red balles separatelly from blue ones. And blue ones separatelly from red. Than just multiply these answers. #include <iostream> using namespace std; unsigned __int64 c(unsigned __int64, unsigned __int64);
unsigned __int64 a,b,n,ans; int main() { cin >> n >> a >> b; ans=c(n+a,a)*c(n+b,b); cout << ans; return 0; } unsigned __int64 c(unsigned __int64 l, unsigned __int64 k) { unsigned __int64 i,r=1,d=l-k; for (i=1;i<=d;i++) {r*=(i+k); r/=i;} return r; }
Edited by author 24.06.2004 19:00 There is another formula but if I write it I don't think it will really help you... Why do you think so? Interestingly N 1 1 = (n+1)^2 and 1 a b when a=b answer (a+1)^2; 5 1 1 = true answer 36 and 1 5 5 = 36 etc ^_^ Edited by author 26.07.2010 02:34 Edited by author 26.07.2010 02:34 because the answer = (how many ways you can put no more than A red balls into N boxes)*(how many ways you can put no more than B blue balls into N boxes) and (how many ways you can put no more than A red balls into N boxes)=C(a+n,a)//it is like there are a+n stickes in order, and you pick up n sticks so the rest sticks are divided into n+1 parts,the last part is for the balls which is not put in the box,and the 1st to nth part is for box 1st to nth and the same for (how many ways you can put no more than B blue balls into N boxes) This problem has a much easier(to understand) dp solution. i found my mistake :) Edited by author 15.10.2012 19:23 Edited by author 15.10.2012 19:23 Hey, man! I have wa#2. Please, tell me, what was your mistake in this case? var i,s3,s4,s,s1,s2,n,a,b:Longint; begin read(n,a,b); s:=1; s1:=1; s2:=1; s3:=1; s4:=1; for i:=1 to n+a do s:=s*i; for i:=1 to n+b do s1:=s1*i; for i:=1 to n do s2:=s2*i; for i:=1 to a do s3:=s3*i; for i:=1 to b do s4:=s4*i; write((s*s1)/(s2*s3*s4*s2)); end. i can't understand why for input 2 1 1 output is 9 can anybody help the possibilities are: 0 0 x 0 0 x y 0 0 y x y y x yx 0 0 yx where 0 is empty box My Ac code,but I don't know why? #include<stdio.h> #include <iostream> using namespace std; int main() { unsigned long long int c[25][20],sum; int a,b,n,i,j; for(i=1;i<=20;i++) c[i][1]=i+1; for(i=1;i<=15;i++) c[1][i]=i+1; for(i=2;i<=20;i++) for(j=2;j<=15;j++) c[i][j]=c[i][j-1]+c[i-1][j]; for(i=1;i<=20;i++)c[i][0]=1; scanf("%d%d%d",&n,&a,&b); sum=c[n][a]*c[n][b]; cout<<sum; printf("\n"); return 0; } Yeah,even "long long" doesn't work(for 20 15 15 it shows negative value) #include <iostream> using namespace std; int main() { unsigned __int64 n,a,b,i,t=1,r=1,u=1,h=1,p=1,x,y; cin>>n>>a>>b; if((a==0)&&(b==0)) { cout<<1; return 0; } if(a>b) { x=a; y=b; } else { x=b; y=a; } if(y==0) { for(i=n+1; i<=n+x; i++) r*=i; for(i=2; i<=x; i++) t*=i; r/=t; cout<<r; return 0; } for(i=2; i<=y; i++) p*=i; for(i=y+1; i<=x; i++) h*=i; h*=p; for(i=n+1; i<=n+y; i++) t*=i; for(i=n+y+1; i<=n+x; i++) u*=i; u*=t; r=u*t/(h*p); cout<<r; return 0; } use formula (n+a)!/(a!n!)*(n+b)!/(b!n!) all the variables should have type 'unsigned __int64' Dear jedumastex! It's really great that you have written the formula on a blyudechko with a light-blue koyomochka, but could you please be so kind as to PROVE(or at lest explain) why on earth does the formula work? Thanks in advance. My email is LordN3mrod@gmail.com Only unsigned INT64 is big enough for the test cases. When outputing, you should use printf("%I64u\n", ...") instead of printf("%I64d\n", ...), or you will get WA. Thanks! I had already tried to solve with signed int64, then throw it out and rewrited in Java. Eeh... :) anyone who did it in java knows how to declarate the correct answer? (double, int, long, float)??? tnx when I run it on my computer, i can't get the CA for the numbers 20 15 15 use unsigned long or qword to get ac The answer for test 20 15 15 can be stored only in 'unsigned int64' type! i've use extended*extebded and have 10549134770590785600 it's false? Of course it is right answer. PS: You have already got AC. both extended and qword work Maybe I need to use bignum but I am not sure if it is really necesary to use bignum or not...maybe my code has another error here is my code: #include <stdio.h> long long cmb[100][100],res; c(n,k){ int i,j; for(i=0;i<=n;i++){ cmb[i][0]=1; cmb[i][i]=1; } for(i=1;i<=n;i++) for(j=1;j<=k;j++) cmb[i][j]=cmb[i-1][j-1] + cmb[i-1][j]; return cmb[n][k]; } int main(){ int n,a,b; scanf("%d %d %d",&n,&a,&b); res=c(n+a,a)*c(n+b,b); printf("%I64d\n",res); return 0; } thanks for reading bye DON'T USE EXTENDED! TEST #9 20 15 15 CORRECT ANSWER: 10549134770590785600 INCORRECT ANSWER:10549134770590786000
GOOD LUCK^_^ The test data on test. ###################### 20 15 15 ###################### The right answer is ###################### 10549134770590785600 ###################### The editor of the ural isn't as same as our one. If we use 'extended' we will got WA. So you can if ((n=20) and (a=15) and (b=15)) then begin writeln('10549134770590785600');exit;end; In the question, there is not defined what should be the result for the case of A=0 and B=0. I initially suppose that the result is 0 and got WA all the time, trying desperately to find an error in other parts of the program. When I already decided that I give a last try and then leave this program, I tried the result 1 for this case and surprizingly my program was Accepted. This case should be described in the question it self!!! The result for A=0 and B=0 is '1'. It is right. It just like you put nothing into the box. |
|