HDU 4283 You Are the One(区间dp)
来源:互联网 发布:网站常用数据库 编辑:程序博客网 时间:2024/05/29 11:53
题目分析
其实就是出队入队问题,考虑如何出队入队才能让屌丝值最少,无语(写道题还虐单身狗!!)。状态转移方程不好想,具体看代码吧!!
#include <cstdio>#include <cstring>#include <iostream>#include <algorithm>using namespace std;const int maxn = 105;const int INF = 0x3f3f3f3f;//这道题的思路有点拐弯,1自己完全晕了!!!int val[maxn], sum[maxn], dp[maxn][maxn];int main(){ int T, n; scanf("%d", &T); for(int kase = 1; kase <= T; kase++){ scanf("%d", &n); sum[0] = 0; for(int i = 1; i <= n; i++){ scanf("%d", &val[i]); sum[i] = sum[i-1] + val[i]; } memset(dp, 0, sizeof(dp)); for(int i = 1; i <= n; i++) for(int j = i+1; j <= n; j++) dp[i][j] = INF; for(int len = 1; len <= n; len++){ for(int i = 1; i+len <= n; i++){ int j = i+len; //dp[i][j]表示对于i到j这个区间所得到的最小花费 for(int k = i; k <= j; k++) //这里表示让第i个人第k个出场,那么很明显(i+1, k)个人要在i前面出场,后面的人因为排在了前面(k-i+1)个人后面所以还需要加上对于的屌丝值 dp[i][j] = min(dp[i][j], val[i]*(k-i)+dp[i+1][k]+dp[k+1][j]+(k-i+1)*(sum[j]-sum[k])); } } printf("Case #%d: %d\n", kase, dp[1][n]); } return 0;}
0 0
- HDU 4283 You Are the One 区间dp
- hdu 4283 You Are the One 区间dp
- HDU 4283 You Are the One(区间DP)
- hdu 4283 You Are the One(区间dp)
- HDU --4283--You Are the One--区间DP
- hdu 4283 You Are the One(区间DP)
- HDU 4283 You Are the One(区间dp)
- HDU 4283 You Are the One 区间dp
- HDU 4283 You Are the One (区间DP)
- HDU 4283 You Are the One(区间dp)
- hdu 4283 You Are the One(区间dp)
- Hdu 4283 You Are the One(区间dp)
- HDU 4283 You are the one(区间DP)
- HDU 4283 You Are the One(区间DP)
- HDU 4283 You Are the One (区间dp)
- HDU 4283 You Are the One(区间dp)
- hdu 4283 You are the one 区间dp
- HDU 4283 You Are the One (区间DP)
- 检测内存泄漏的常见工具-LeakCanary
- <![CDATA[<= ]]> <<=>>=&'" 转译Z字符
- ViewPage实现引导页的切换,且滑到最后一页再滑时进入到主页。
- c语言实现一个helloworld
- +-START-+fIiIhEY/P0U6RTpFOnyOjHoeczpzf30/1A==+-END-+ 顺其自然
- HDU 4283 You Are the One(区间dp)
- 红黑树(删除)
- opengl shader内置变量和函数
- 单例模式-Singleton Pattern 确保对象的唯一性——单例模式 (三):饿汉式单例与懒汉式单例的讨论
- XMemcached&Spring集成
- [Lintcode]Merge k Sorted Lists
- m_Timer.Tick += new EventHandler(HandleTimerTick);
- 一个完整的C程序
- iOS 自动布局 Interface Builder