Treats for the Cows 记忆化搜索
来源:互联网 发布:dp是什么意思网络术语 编辑:程序博客网 时间:2024/06/07 03:56
#include<stdio.h>#include<string.h>int hash[2005][2005];int treat[2005];int num;int dfs(int head,int tail,int n);int main(){ int i,k; while(scanf("%d",&num)!=EOF) { memset(hash,0,sizeof(hash)); for(i=0;i<num;i++) scanf("%d",&treat[i]); k=dfs(0,num-1,1); printf("%d\n",k); } return 0;}int dfs(int head,int tail,int n){ int max=0,k1,k2; if(n>num) return 0; if(hash[head][tail]) return hash[head][tail]; k1=n*treat[head]+dfs(head+1,tail,n+1); k2=n*treat[tail]+dfs(head,tail-1,n+1); max=k1>=k2?k1:k2; hash[head][tail]=max; return max;}
DP我不会,我只会DFS+记忆化来剪枝。。。。。
- Treats for the Cows 记忆化搜索
- poj 3186 Treats for the Cows(滚动DP OR 记忆化搜索)
- Treats for the Cows
- POJ3186:Treats for the Cows
- poj3186 Treats for the Cows
- POJ3186 Treats for the Cows
- Treats for the Cows POJ
- 33. Treats for the Cows
- Treats for the Cows(dp)
- POJ 3186 Treats for the Cows
- poj(3186)Treats for the Cows
- POJ3186:Treats for the Cows(区间DP)
- poj 3186 Treats for the Cows
- POJ3186——Treats for the Cows
- POJ 3186 Treats for the Cows
- POJ 3186 Treats for the Cows
- POJ3186:Treats for the Cows 区间DP
- POJ 3186 Treats for the Cows (DP)
- 零售连锁商业智能分析(BI)实例(ZT) <1>
- window7 搭建SVN 本地可以访问 其他机器无法访问
- 倒计时
- 表单处理
- 零售连锁商业智能分析(BI)实例(ZT) <2>
- Treats for the Cows 记忆化搜索
- 单片机实时温度采集并通过串口通信上传电脑显示
- Perl 脚本中使用ls 获取目录名或文件名注意事项
- js 初学笔记
- 集群NAS技术架构
- Android Native code 的绘图方法2
- django创建博客
- ORACLE LOB 大对象处理
- 广度遍历二叉树