uva 10118 Free Candies
来源:互联网 发布:海思970 高通835 知乎 编辑:程序博客网 时间:2024/06/09 11:38
#include<cstdio>#include<cstring>#include<algorithm>using namespace std;int vis[30],top[5],dp[60][60][60][60],n,d[4][60];int dfs(int k){int &t=dp[top[0]][top[1]][top[2]][top[3]];if(t != -1) return t;t=0;if(k >= 5 || top[0]+top[1]+top[2]+top[3] == n * 4) return t;for(int i=0;i<4;i++){if(top[i] >= n) continue;top[i]++;if(vis[d[i][top[i]]]){vis[d[i][top[i]]]=0;t=max(dfs(k-1)+1,t);vis[d[i][top[i]]]=1;}else{vis[d[i][top[i]]]=1;t=max(dfs(k+1),t);vis[d[i][top[i]]]=0;}top[i]--;}return t;}int main(){while(scanf("%d",&n) == 1 && n){for(int i = 1;i <= n; i++){for(int j = 0;j < 4; j++){scanf("%d",&d[j][i]);}}memset(vis,0,sizeof(vis));memset(top,0,sizeof(top));memset(dp,-1,sizeof(dp));printf("%d\n",dfs(0));}}
阅读全文
0 0
- uva 10118 Free Candies
- uva 10118 - Free Candies
- UVA - 10118 Free Candies
- uva 10118 - Free Candies
- UVA 10118 - Free Candies
- UVA - 10118 Free Candies
- UVA - 10118 Free Candies
- UVa 10118 Free Candies
- uva 10118 free candies
- UVA 10118 Free Candies
- UVA 10118 Free Candies
- uva 10118 Free Candies
- UVA 10118 Free Candies
- uva 10118Free Candies
- uva 10118 Free Candies
- uva 10118 Free Candies
- Free Candies - UVa 10118 dp
- uva 10118 (Free Candies)(DP)
- 洛谷 3941 入阵曲 规律题
- PHPmemo
- 微信开发调试方法
- Xcode9学习笔记33
- 注释符号
- uva 10118 Free Candies
- uva1629 切方格使得每个方格中只有一个物品,求最少切割费用 记忆化搜索
- [noip2003]麦森数(高精度+ksm)
- Xcode9学习笔记34
- linux基础(二)系统结构、文件管理、正则表达式
- Java线程池的几种实现 及 常见问题讲解
- 11月05日解题报告
- 燕山大学电子通信系生产实习单片机调试
- Xcode9学习笔记35