HDU 4283 You Are the One(区间DP)
来源:互联网 发布:java整形转换为字符串 编辑:程序博客网 时间:2024/05/29 02:34
Description
Input
第一行一整数
Output
输出这
Sample Input
2
5
1
2
3
4
5
5
5
4
3
2
2
Sample Output
Case #1: 20
Case #2: 24
Solution
枚举第
Code
#include<cstdio>#include<iostream>#include<cstring>#include<algorithm>#include<cmath>#include<vector>#include<queue>#include<map>#include<set>#include<ctime>using namespace std;typedef long long ll;#define INF 0x3f3f3f3f#define maxn 111int T,n,a[maxn],sum[maxn],dp[maxn][maxn];int dfs(int l,int r){ if(l>=r)return 0; if(dp[l][r]!=-1)return dp[l][r]; dp[l][r]=INF; for(int i=l;i<=r;i++) dp[l][r]=min(dp[l][r],(i-l)*a[l]+dfs(l+1,i)+dfs(i+1,r)+(i-l+1)*(sum[r]-sum[i])); return dp[l][r];}int main(){ int res=1; scanf("%d",&T); while(T--) { scanf("%d",&n); sum[0]=0; for(int i=1;i<=n;i++)scanf("%d",&a[i]),sum[i]=sum[i-1]+a[i]; memset(dp,-1,sizeof(dp)); printf("Case #%d: %d\n",res++,dfs(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)
- ACM 1392 Surround the Trees
- 程序员必须掌握的8大排序算法(一):直接插入排序
- (百度百科)CSS盒子模型
- 572. Subtree of Another Tree
- Shader学习基础之六UsePass和#include
- HDU 4283 You Are the One(区间DP)
- oracle按章报错
- 一张图搞懂android事件分发机制
- http1.0 和 http1.1区别?
- 关于mysql中使用枚举类型还是int类型存取有限个固定值
- java大数算法完成五则运算之加减
- spark-streaming 读取kafka的方式
- 51Nod-1085-背包问题
- springboot + mongodb 查询实例