HDU 4283 - You Are the One(区间DP)
来源:互联网 发布:淘宝买家如何升级星级 编辑:程序博客网 时间:2024/05/29 08:14
题目:
http://acm.hdu.edu.cn/showproblem.php?pid=4283
用两种形式写了一下。。
AC。
#include <iostream>#include <cstdio>#include <cstring>#include <cmath>using namespace std;const int inf = 0x3f3f3f3f;const int maxn = 105;int v[maxn], sum[maxn];int dp[maxn][maxn];int dfs(int l, int r){ if(l > r) return 0; if(dp[l][r] != inf) return dp[l][r]; for(int i = l; i <= r; ++i) { int cnt = dfs(l+1, i) + dfs(i+1, r) + v[l]*(i-l) + (i-l+1)*(sum[r]-sum[i]); dp[l][r] = min(dp[l][r], cnt); } return dp[l][r];}int main(){ int T, ca = 1; scanf("%d", &T); while(T--) { int n; scanf("%d", &n); sum[0] = 0; for(int i = 1; i <= n; ++i) { scanf("%d", &v[i]); sum[i] = sum[i-1] + v[i]; } memset(dp, inf, sizeof(dp)); dfs(1, n); printf("Case #%d: %d\n", ca++, dp[1][n]); } return 0;}
#include <iostream>#include <cstdio>#include <cstring>#include <algorithm>using namespace std;const int inf = 0x3f3f3f3f;const int maxn = 105;int val[maxn], sum[maxn];int dp[maxn][maxn];int main(){ //freopen("in", "r", stdin); int T, ca = 1; scanf("%d", &T); while(T--) { int n; 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 j = 1; j <= n; ++j) { for(int i = j; i >= 1; --i) { for(int k = 1; k <= j-i+1; ++k) { dp[i][j] = min(dp[i][j], dp[i+1][i+k-1]+val[i]*(k-1)+dp[i+k][j]+k*(sum[j]-sum[i+k-1])); } } } printf("Case #%d: %d\n", ca++, 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)
- 【vim】vim 的backspace不能使用
- 对串级PID和单级PID的理解(基于匿名微型六轴)
- taobao 登录功能代码 淘宝
- Spring 面向切面编程AOP
- 推荐!国外程序员整理的机器学习资源大全
- HDU 4283 - You Are the One(区间DP)
- 黑马程序员——————java基础之Io二
- hdu 5358 First One (尺取法)
- Nexus7安装NetHunter笔记
- HDU 1874 畅通工程续(最短路)
- Convolutional-Neural-Network (CNN)框架详解
- HDOJ 5358 First One 暴力
- 花生壳+tomact 将个人电脑搭建服务器
- JavaEE 新玩法