UVA10118 - Free Candies
来源:互联网 发布:淘宝活动派发报名任务 编辑:程序博客网 时间:2024/06/06 10:38
我有话说:
这道题比较简单,总思路就是dfs+记忆化搜索
#include <iostream>#include <cstdio>#include <algorithm>#include <cstring>#include <vector>#include <queue>using namespace std;const int maxn=100;int n;int candy[4][maxn],vis[maxn],top[4];int dp[maxn][maxn][maxn][maxn];int dfs(int cnt){ int& ans=dp[top[0]][top[1]][top[2]][top[3]]; if(ans!=-1)return ans; if(cnt==5)return ans=0; ans=0; for(int i=0;i<4;i++){ if(top[i]==n)continue; int color=candy[i][top[i]]; top[i]++; if(vis[color]){ vis[color]=0; ans=max(ans,dfs(cnt-1)+1); vis[color]=1; }else{ vis[color]=1; ans=max(ans,dfs(cnt+1)); vis[color]=0; } top[i]--; } return ans;}int main(){ while(scanf("%d",&n)==1&&n){ for(int i=0;i<n;i++){ for(int j=0;j<4;j++){ scanf("%d",&candy[j][i]); } } memset(top,0,sizeof(top)); memset(dp,-1,sizeof(dp)); memset(vis,0,sizeof(vis)); printf("%d\n",dfs(0)); } return 0;}
0 0
- UVa10118 - Free Candies
- UVA10118 - Free Candies
- [逆向DP]UVa10118 - Free Candies
- UVa10118 - Free Candies dp+简单模拟
- 算法竞赛入门经典 第二版 习题9-2 免费糖果 Free Candies uva10118
- Free Candies
- uva10118
- Uva10118
- ZOJ 1227 Free Candies
- 10118 - Free Candies
- uva 10118 Free Candies
- hdu 1514-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
- ArrowDownloadButton下载按钮从点击到下载完成特效
- QT即时计时器
- hello, blog!
- 容斥原理的证明
- Oracle,实现一条记录的上移下移
- UVA10118 - Free Candies
- ORACLE wmsys.wm_concat()函数把某列数据整合到一起
- 【Android杂谈】关于Handler理解
- linux应用程序桌面图标
- First day!
- js javascript:void(0) 真正含义
- 平衡二叉树汇总
- [持续更新]HTML5学习笔记(二)
- Unity 3D 存档实现