The two questions are identical.
Test instructions: Given a series of recursive relationships, but because these recursion is very complex, so it takes a long time to push, so I want to program to output the answer within a limited time.
W (A, B, c):
If there is a value less than or equal to 0 in A,b,c, then the value of W (A, B, c) is 1
If there is a value greater than 20 in a,b,c, then the value of W (A, B, c) is W ( +,-)
If A<b<c, then W (A, B, c) =w (A, B, c-1) + W (A, b-1, C-1)-W (A, b-1, c)
Otherwise w (A, B, c) =w (A-1, B, c) + W (A-1, B-1, C) + W (A-1, B, C-1)-W (A-1, B-1, C-1)
I tried, just press this input, and then a=15,b=15,c=15, basically is waiting for the end, the continuous recursion will take a few hours, so my first idea is: Find the law!!! Yes, I'm just so stupid, no way.
I looked for a long time, and then by the method of the table almost found half of the law, I am filled with joy to use these laws to replace the part of the recursive Tuirang answer is easy to find out, and then I tried the value of my attempt is also very fast output, so I die submitted, T. I "I was speechless ah, I thought it was I find the law is not deep enough, and then" "in short, and can not find out the law I finally gave up, the coarse look at the answer: memory of the search.
Good-bye, my friend. I was totally wrong about the truth. "I'm dead in the end of the law I'm looking for. Modify the memory, after submitting" WA "
I think of a word: Don't be depressed, short is not your fault, raise your head to tell everyone, you are not only short, you are ugly "
Yes, my train of thought is completely wrong, and I find the law is wrong!
Well, I think, after I get rid of my damn rule, I finally got a "'" and that's it, and the code, by the way, attaches me to the law of death, well, it's wrong.
1#include <stdio.h>2#include <string.h>3#include <math.h>4 intdp[ +][ +][ +];/*5 void Fun () {6 int i,j,k;7 For (i=0;i<=20;i++) {8 For (j=0;j<=20;j++) {9 For (k=0;k<=20;k++) {Ten if (i<=0| | j<=0| | k<=0) dp[i][j][k]=1; One else if (j==1&&k==1) dp[i][j][j]=i+1; A else if (j>=i| | k>=i) Dp[i][j][k]=pow (2,i); - } - } the } - }*/ - intWintAintBintc) { - if(a<=0|| b<=0|| c<=0)return 1; + if(a> -|| B> -|| C> -)returnW -, -, -); - if(Dp[a][b][c])returnDp[a][b][c]; + if(a<b&&b<c) { ADp[a][b][c]=w (a,b,c-1) +w (a,b-1, C-1)-W (a,b-1, c); at returnDp[a][b][c]; - } -Dp[a][b][c]= (W (A1, B,c) +w (A-1, B-1, c) +w (A-1, b,c-1)-W (A1, B-1, C-1)); - returnDp[a][b][c]; - } - in intMain () { -Memset (DP,0,sizeof(DP)); to //Fun (); + inta,b,c; - while(SCANF ("%d%d%d", &a,&b,&c)!=eof&& (a!=-1|| b!=-1|| c!=-1)){ theprintf"W (%d,%d,%d) =", a,b,c); *printf"%d\n", W (a,b,c)); $ }Panax Notoginseng return 0; -}
View Code
hdu1331&&hdu1579 Memory Search (DP+DFS)