HDU4283 You Are the One 有点难的区间DP
来源:互联网 发布:70d锦纶单股网络丝 编辑:程序博客网 时间:2024/05/22 04:33
有N个人要出场,每个人有个不爽的值,如果他第i个出场 那么 他的愤怒值为 num[i]*(i-1),求怎么样排出场顺序,能使得总得愤怒值最小
dp[i][j] 当然表示第i个人 到第j个人这个区间的最小愤怒值,这里要注意的是 只对这个区间进行考虑, 比如 dp[2][5],只需要考虑2到5号人的出场安排,此区间前面的不需要去考虑
解析什么的 绝对是 爱神 的比较给力 也比较清晰,咱这语文水平就不表达了
http://blog.csdn.net/acm_cxlove/article/details/7964594
#include<iostream>#include<cstdio>#include<list>#include<algorithm>#include<cstring>#include<string>#include<queue>#include<stack>#include<map>#include<vector>#include<cmath>#include<memory.h>#include<set>#define ll long long#define eps 1e-8#define inf 0xfffffff//const ll INF = 1ll<<61;using namespace std;//vector<pair<int,int> > G;//typedef pair<int,int > P;//vector<pair<int,int> > ::iterator iter;////map<ll,int >mp;//map<ll,int >::iterator p;int dp[1000 + 5][1000 + 5];int num[1000 + 5];int sum[1000 + 5];int n;void clear() {memset(num,0,sizeof(num));memset(sum,0,sizeof(sum));memset(dp,0,sizeof(dp));for(int i=1;i<=n;i++)for(int j=i+1;j<=n;j++)dp[i][j] = inf;}int main() {int t;int Case = 0;scanf("%d",&t);while(t--) {scanf("%d",&n);clear();for(int i=1;i<=n;i++) {scanf("%d",&num[i]);sum[i] = sum[i-1] + num[i];}for(int k=1;k<=n;k++) {for(int i=1;i<=n-k;i++) {int j = i + k;for(int p=1;p<=j-i+1;p++)dp[i][j] = min(dp[i][j],dp[i+1][i+p-1]+dp[i+p][j] + (p-1)*num[i] + (sum[j]-sum[i+p-1])*p);}}printf("Case #%d: %d\n",++Case,dp[1][n]);}return EXIT_SUCCESS;}
2 0
- HDU4283 You Are the One 有点难的区间DP
- hdu4283 You Are the One(区间DP)
- HDU4283:You Are the One(区间DP)
- hdu4283---You Are the One(区间dp)
- hdu4283 you are the one 区间DP
- HDU4283:You Are the One(区间DP)
- HDU4283 You Are the One 区间DP
- hdu4283 You Are the One(区间DP)
- hdu4283 You Are the One 区间DP
- HDU4283:You Are the One(区间DP)
- HDU4283——You Are the One(区间DP)
- hdu4283 You Are the One(区间DP)
- hdu4283 You Are the One(区间dp,思考)
- HDU4283 You Are the One(区间dp)
- hdu4283——You Are the One(区间dp)
- HDU4283——You Are the One(区间dp)
- HDU4283——You Are the One (区间DP)
- HDU4283 You Are the One (DP)
- C# 访问PostgreSQL 数据库
- 如何在Activity中启动另一个Activity与值传递
- 扫雷小游戏
- QT4.8-VS2008-安装
- OpenGL进阶(十七) - 深入理解OpenGL
- HDU4283 You Are the One 有点难的区间DP
- Eclipse的快捷键
- .NET 访问PostgreSQL数据库
- 黑马程序员_Java基础01_基础语法
- 吉日嘎拉通用权限管理系统
- 两个最接近的数之间的差值-红黑树-快速排序
- AOJ-AHU-OJ-34 Euchre Results
- 判断网络连接情况
- 细说C++中的new与delete