POJ 3186 Treats for the Cows(区间DP)
来源:互联网 发布:本地系统 网络受限 编辑:程序博客网 时间:2024/06/04 01:29
the question is here
this DP question want us to chose treats and find the maximum value . We can see this is a dp question , and the equation which I write below means the maximum value for i to j can be decided by the sub region .
#include <iostream>#include <cstring>#define ll long long#define maxn 105using namespace std;//dp[i][j] = max{dp[i+1][j]+a[i]*(n+i-j),dp[i][j-1]+a[j]*(n+i-j)}int dp[2005][2005];int v[2005];int main(){ int n=0; cin>>n; for(int i=1;i<=n;i++) { cin>>v[i]; } for(int i=1;i<=n;i++) { dp[i][i] = v[i]*n; // init } for(int i = n;i>0;i--) { for(int j=i;j<=n;j++) { dp[i][j] = max(dp[i+1][j]+v[i]*(n+i-j),dp[i][j-1]+v[j]*(n+i-j)); } } cout<<dp[1][n]<<endl; return 0;}
阅读全文
0 0
- 【区间dp】Treats for the Cows POJ
- poj 3186 Treats for the Cows (区间dp)
- 【POJ 3186 】Treats for the Cows (区间DP)
- POJ 3186 Treats for the Cows(区间DP)
- poj 3186 Treats for the Cows(区间dp)
- poj 3186 Treats for the Cows(区间dp)
- POJ 3186 Treats for the Cows (区间DP 水题)
- POJ 3186 Treats for the Cows(区间DP)
- POJ 3186 Treats for the Cows (区间DP)
- 区间DP-POJ-3186-Treats for the Cows
- poj 3186 Treats for the Cows(区间dp)
- POJ 3186 Treats for the Cows (区间DP)
- poj 3186 Treats for the Cows (区间DP)
- poj 3186 Treats for the Cows(区间dp)
- POJ 3186 Treats for the Cows (区间DP)
- Poj 3186 Treats for the Cows【区间dp】
- POJ-3186 Treats for the Cows (区间DP)
- POJ 3186 Treats for the Cows(区间dp)
- IntelliJ Idea 常用快捷键列表
- Lua知识点九
- 你真的懂Handler.postDelayed()的原理吗?
- 《算法心得-高效算法的奥秘(原书第2版)》pdf
- 学习记录
- POJ 3186 Treats for the Cows(区间DP)
- Invoking Page() in async task.
- 中英文对照 —— 饮食与美食
- maven pom.xml添加日志支持
- druid 连接池
- Unity plyGame插件技能模块分析
- STL--<vector>学习
- 《Using OpenRefine》翻译~12
- Android.mk宏定义demo