【动态规划】[luoguP2858 USACO06FEB]奶牛零食Treats for the Cows
来源:互联网 发布:java程序设计培训学校 编辑:程序博客网 时间:2024/05/22 01:40
题目
比较裸 比较简单的区间dp
我们每次都是从两头拿掉其中的一个 但是具体是哪一个 我们不知道 但我们知道的是一定是从两头拿
我们设f[i][j]为剩下没有拿的最左端是第i个 最右端是第j个 能出状态转移方程式
i + 1就是取了最左边的 从而加上那件东西的价值 j - 1同理
至于n - j - i就是当前是拿到第几次了 这个有可能一下子想不出来吧
代码实现更新一个记忆化搜索的 没有了n - j - i而是直接用一个变量记录当前是第几次了 毕竟是DFS。。
代码如下
#include<iostream>#include<cstdio>#include<cctype> using namespace std; #define in = read(); typedef long long ll; typedef unsigned int ui; const ll size = 5000 + 100; int n; int ans; int a[size]; int f[size][size];inline ll read(){ ll num = 0 , f = 1; char ch = getchar(); while(!isdigit(ch)){ if(ch == '-') f = -1; ch = getchar(); } while(isdigit(ch)){ num = num*10 + ch - '0'; ch = getchar(); } return num*f;}ll dfs(ll x , ll y , ll z){ if(z == n + 1) return 0; if(f[x][y]) return f[x][y]; f[x][y] = max(dfs(x + 1 , y , z + 1) + a[x]*z , dfs(x , y - 1 , z + 1) + a[y]*z); return f[x][y];}int main(){ n in; for(register int i=1;i<=n;i++) a[i] in; printf("%d" , dfs(1 , n , 1));}//COYG
阅读全文
0 0
- 【动态规划】[luoguP2858 USACO06FEB]奶牛零食Treats for the Cows
- O - Treats for the Cows POJ 3186 ( 动态规划+区间 )
- poj 3186 Treats for the Cows 动态规划
- 动态规划训练20 [Treats for the Cows POJ
- POJ-3186-Treats for the Cows-动态规划DP
- 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)
- 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
- POJ3186——Treats for the Cows
- js-多个果冻按钮之当前果冻按钮弹性特效
- 下载Excel文件模板 ---文件下载--SSM
- 微信小程序分享页面
- C++11 并发指南六(atomic 类型详解四 C 风格原子操作介绍)
- golang实现微信公众号发红包功能
- 【动态规划】[luoguP2858 USACO06FEB]奶牛零食Treats for the Cows
- Code Festival 2017 qualA D Four Coloring[构造]
- aop实现
- mt2503为什么使用test machine时CB language setting不起作用?
- 架构师日记——ActiveMQ简介
- Visual Studio 2017 新建一个C#项目(DotNetty应用)
- javascript取My97 DatePicker控制中的日期
- PHP解决网站大数据大流量与高并发方案
- Java的23种设计模式详解