HDU 4283 You Are the One (区间DP)
来源:互联网 发布:sql用于授权语句的是 编辑:程序博客网 时间:2024/06/06 20:36
自己功夫不到家,这个题根本没想到用区间DP。
下面说一下自己做DP的一点点感悟:虽然DP有区间、数位、树形等,但在推状态转移方程时主要还是两个方法:正推和逆推。在正推和逆推的过程中,状态就有可能出来,对应的也会想到它是一个什么DP。不过枚举DP的类型可能也是个做法。。。在推导过程中,要确定满足最优子结构的目标状态是怎样的,写出方程后还要看其是否满足无后效性。
最重要的还是要多做题积累经验反思总结。。这题没想出来只能怪自己功夫不到家。
参考题解:点击打开链接
我的代码:
#include<cstdio>#include<iostream>#include<cstring>#include<algorithm>using namespace std;const int maxn = 105;const int inf = 0x3f3f3f3f;int a[maxn],s[maxn],n,dp[maxn][maxn];int main(){ int cas; scanf("%d",&cas); for(int T=1;T <= cas;T++){ scanf("%d",&n); for(int i=1;i<=n;i++){ scanf("%d",&a[i]); s[i] = s[i-1] + a[i]; } memset(dp,0,sizeof(dp)); for(int i=n;i>=1;i--){ for(int j=i;j<=n;j++){ dp[i][j] = i == j ? 0 : inf; for(int k=i;k<=j;k++){ dp[i][j] = min(dp[i][j],(k-i)*a[i]+dp[i+1][k]+dp[k+1][j]+(k-i+1)*(s[j]-s[k])); //cout<<i<<" "<<j<<" "<<k<<" "<<dp[i][j]<<endl; } } } printf("Case #%d: %d\n",T,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)
- 快速排序
- Android Studio not find in root project android()
- 解决Win10 10240版 cisco vpn client无法安装问题
- 【PHP】php通过javascript判断不同设备分辨率来调用不同的css class
- ubuntu 下安装jdk 和配置java环境变量
- HDU 4283 You Are the One (区间DP)
- Leetcode# 82 Remove Duplicates from Sorted List II
- django环境搭建
- 状压dp Mondriaan's Dream poj2411
- 虚析构函数(√)、纯虚析构函数(√)、虚构造函数(X)
- C语言之函数调用18—多字符串排序
- HDU 3853 向下向右找出口问题-期望dp
- Activity技巧三重奏之二:随时随地的退出程序
- 使用rpmbuild来创建自己的RPM