I have correct answer at least on first test, but I got WA1! Why? Is first test different with a test in a problem's description? I write each line of my answer via Scala println (similar with Java), and read with StdIn.readLine. Edited by author 25.08.2019 19:14 Edited by author 25.08.2019 19:15 Hello, I am not that strong in DP but I have been trying hard to understand the problem. I tried coming up with a solution however got WA. I cannot completely understand the hints given before, PLEASE HELP !!! There are two dp-approaches already described on the webboard So I have accepted with dp I have two dp Stirling numbers of the second kind and factorial Then precalculate answer array I have seen the 2 DP solutions however I still don't understand how do they arrive at the relation? Can you describe in detail if possible, Please ! There are X groups consisting of equal numbers. X=1,2,..n. What does it mean, to put some '<' and '>' signs between them? It is just to define some order relation. Just assign one group as the greatest, another group as the second greatest etc. So we find number of ways to make groups and multiply it by number of ways to make ordering https://ideone.com/00UUdfThanks to the author for the interesting task in combinatorics and integer partitioning! use DP, mainly involved with: permutation and combination A(n,k) C(n,k) or, you can think about there is a x-Axis. two points (a, b) can be placed --a--b-- --b--a-- || --(ab)-- the first two solution has two groups, and the last one has one groups for the overlap.
Let a be the number of objects. Let b be the number of objects in a group. Let A[a] is the number of permutations of a objects ( A[2] = 2, A[3] = 2*3, A[4] = 2*3*4...) So: f[a][b] is the number of groups with b objects. You have the formula: f[a][b] = f[a-1][b] * b + f[a-1][b-1]; And the result = f[n][1] * A[1] + f[n][2] * A[2] + ... + f[n][3] * A[3] A group is formed by equal objects in a relation. For example: a = b < c = d (2 groups ab and cd) a = b < c < d (3 groups ab, c and d) ... I think when N is increased to 1000, everyone will solve it by DP or maths, not cheat :-) thank you for your idea. I had learnt a lot from yours. Apply the GOOD JOB for College ACMers to Make Large Money and Become a Millionaire Hello, We need large no. of dedicated and hard working ACMers. The payment is good so we need ACMers to be efficient. All you have to do to get the job is to sign up at our websites. The link of our websites are given below. http://www.PaisaLive.com/register.asp?3556638-4847933 After the registration, a confirmation email will be sent to your specified email address. Please click on the link inside the confirmation email to activate your account and recieve ACM work instantly. For any other queries you can mail the administrator. Miss Juliet Admin paisalive.com Yes, you can have this case. Your hint has helped my solve the problem. KEYWORDS: Stirling numbers of 2nd kind, Factorial z = fact(z)/(2*pow(log(2),n+1)); if(fmod(z,1)>=0.5) z = floor(z) + 1; else z = floor(z); I tried the example test case and got true, but got WA with 1st test case... T_T I sent your formula and got AC. Try to output answer so: cout << fixed << setprecision(0) << z; or so: printf("%.0lf",z); And you must use double instead of float function g(x,k:longint):comp; var i:longint; q:comp; begin q:=1; for i:=1 to k do q:=q*i; g:=q*x; end; var f:array[0..20,0..20] of longint; a:array[0..20] of comp; i,j,n,k:longint; begin for i:=0 to 10 do begin f[i,1]:=1; f[i,i]:=1; end; f[0,1]:=0; for i:=1 to 10 do for j:=2 to i-1 do f[i,j]:=f[i-1,j-1]+f[i-1,j]*j; for i:=2 to 10 do for j:=1 to 10 do a[i]:=a[i]+g(f[i,j],j); readln(n); while n>0 do begin writeln(a[n]:0:0); readln(n); end; end. Any hint on how to count all relations? Thanks! use DP. your function will be F(n, k) where N is the amount of number in the relation and K is the number of groups. For example: a=b=c=d - 1 group a=b<c=d - 2 groups a<b<c<d - 4 groups equal numbers form one group. Edited by author 09.05.2005 05:40 It's a maths problem. Like that puting N balls into M boxes. Edited by author 28.01.2008 07:01 Thank you! The idea of puting balls into boxes helped me. You must use PolyLogaryphm, formula a[n]=1/2*PolyLog[-n,1/2]; P.S. AC 0.015 229 kb what's the answer of 5 = =" Can u tell me..? I have no hint.. T_T Can i accept by use relation of sequence? Please help me if 2<n<100!!! There is a recurrence relation for these numbers. something like a(n+1) = 1 + sum {k=1,k=n; binomial(n+1, k)*a(k)} // USU Problem 1142 // Relation // Done by Teh Ming Han #include <iostream.h> int main(){ int i,n; unsigned long fact[10]; fact[1] = 1; for (i=2;i<=10;i++) fact[i] = fact[i-1]*i;
while (!cin.eof()){ cin>>n; if (n>=1) cout<<(fact[n]*(n-1))+1<<endl; else break; } return 0; } the problem is not in your code. your idia is wrong. i looked at your sors. it will only work when there is only one sign '='. Edited by author 01.05.2005 16:01 > > >email at"daniciuc_marian@yahoo.com" HI all For solving this problem use dynamic programming as this way: for finding answer of k... do it: for i:=1 to k do f[k]:=f[k]+c(i,k)*f[k-i]; which c(i,k) is amount of ways to choose i thing from k thing: c(i,k)= k! / (i!*(k-i)!) ans its proof is: variable i is amount of '='s that use if 1time '=' use then it we should choose 2 operand in both sides of = operator and if 2= uses then we should chose 3operand (form k operand that we have)... ans etc. mail me for more explaination: aidin_n7@hotmail.com
|
|