标签:
2 4 25
11 337
1 #include <iostream> 2 #include <cstring> 3 #include <cstdio> 4 using namespace std; 5 const int maxn = 2000; 6 bool e[maxn][maxn],ok[maxn<<1],used[maxn]; 7 int ans[55],link[maxn],n; 8 int dfs(int u) { 9 for(int i = 1; i <= n; ++i) { 10 if(!used[i] && e[u][i]) { 11 used[i] = true; 12 if(link[i] == -1||dfs(link[i])) { 13 link[i] = u; 14 return true; 15 } 16 } 17 } 18 return false; 19 } 20 int solve() { 21 int tmp = 0; 22 memset(link,-1,sizeof(link)); 23 for(int i = 1; i <= n; ++i) { 24 memset(used,false,sizeof(used)); 25 tmp += dfs(i); 26 } 27 return tmp; 28 } 29 int main() { 30 int i,j,t,o; 31 for(i = 1; i*i < (maxn<<1); ++i) ok[i*i] = 1; 32 for(i = 1; i < maxn; ++i) 33 for(j = i + 1; j < maxn; ++j) 34 e[i][j] = ok[i + j]; 35 for(n = 1; n < maxn; ++n) { 36 int tmp = solve(); 37 if(n - tmp > 50) break; 38 ans[n - tmp] = n; 39 } 40 scanf("%d",&t); 41 while(t--) { 42 scanf("%d",&o); 43 printf("%d\n",ans[o]); 44 } 45 return 0; 46 }
HDU 1329 Hanoi Tower Troubles Again!
标签:
原文地址:http://www.cnblogs.com/crackpotisback/p/4411609.html