ural1437

1437

记忆化 模拟倒水过程

 1 #include <iostream>
 2 #include<cstdio>
 3 #include<cstring>
 4 #include<algorithm>
 5 #include<stdlib.h>
 6 #include<vector>
 7 #include<cmath>
 8 #include<queue>
 9 #include<set>
10 using namespace std;
11 #define N 256
12 #define LL long long
13 #define INF 0xfffffff
14 const double eps = 1e-8;
15 const double pi = acos(-1.0);
16 const double inf = ~0u>>2;
17 bool dp[N][N][N];
18 bool o[1010];
19 int n,m,k;
20 void dfs(int i,int j,int g)
21 {
22     if(dp[i][j][g]) return ;
23     dp[i][j][g] = 1;
24     o[i] = 1,o[j] = 1,o[g] = 1;
25     o[i+j] = 1,o[j+g] = 1,o[i+g] = 1;
26     o[i+j+g] = 1;
27     dfs(n,j,g);dfs(i,m,g);dfs(i,j,k);
28     int ii = n-i,jj = m-j,gg = k-g;
29     if(j<=ii) dfs(i+j,0,g);
30     else dfs(n,j-ii,g);
31     if(g<=ii) dfs(i+g,j,0);
32     else dfs(n,j,g-ii);
33     if(i<=jj) dfs(0,i+j,g);
34     else dfs(i-jj,m,g);
35     if(g<=jj) dfs(i,j+g,0);
36     else dfs(i,m,g-jj);
37     if(i<=gg) dfs(0,j,i+g);
38     else dfs(i-gg,j,k);
39     if(j<=gg) dfs(i,0,j+g);
40     else dfs(i,j-gg,k);
41 }
42 int main()
43 {
44     int i,j,g;
45     while(cin>>n>>m>>k)
46     {//cout<<",";
47         memset(dp,0,sizeof(dp));
48         memset(o,0,sizeof(o));
49         dfs(0,0,0);
50 
51         int ans = 0;
52         for(i = 1 ; i <= n+m+k ; i++)
53         if(o[i]) ans++;
54         cout<<ans<<endl;
55     }
56     return 0;
57 }
View Code

 

posted @ 2014-03-28 16:09  _雨  阅读(206)  评论(0编辑  收藏  举报