HDU4283:You Are the One(区间DP)
来源:互联网 发布:介绍编程的书 编辑:程序博客网 时间:2024/06/05 04:51
题意:有个舞台要表演节目,有n个人排成一队,每个人有个屌丝值的单位Pi。如果这个人前边有x个人上台了,这个人的屌丝值就是x*Pi。队列的顺序是固定的,但是舞台有个小黑屋(类似栈),宽度只能容下一个人,长度是无限的,在上台之前可以先进小黑屋然后让别人先上。求让所有人都上台的最小的屌丝值和
思路:
在我感觉,区间DP就是找到一个点,让区间分离而且又能合并的点,像这道题。就可以这么考虑。
比如 1 2 3 4 5是这些人的序号(不是Pi),如果1第是第三个上台的,因为如果1进小黑屋了,那么他后边的所有人都一定比他先上台,所以肯定是2 3都上台了,然后1 上台,至于2 3是怎么上台的就再做讨论
所以方程式就出来了。
这道题就是考虑对于序列 L~R 如果 l 是第 k个上台的,那么
dp[L][R]=min(dp[L]][R],dp[L+1][L+k-1]+dp[L+k][R]+x)
x是 L 第 k个上台所带来的 屌丝值和
#include<stdio.h>#include<string.h>#include<iostream>#include<algorithm>#include<math.h>#include<queue>#include<stack>#include<string>#include<vector>#include<map>#include<set>using namespace std;#define rfor(i,a,b) for(i=a;i<=b;++i)#define lfor(i,a,b) for(i=a;i>=b;--i)#define sfor(i,a,h) for(i=h[a];i!=-1;i=e[i].next)#define mem(a,b) memset(a,b,sizeof(a))#define mec(a,b) memcpy(a,b,sizeof(b))#define cheak(i) printf("%d ",i)#define min(a,b) (a>b?b:a)#define max(a,b) (a>b?a:b)#define inf 0x3f3f3f3f#define lowbit(x) (x&(-x))typedef long long LL;#define maxn 105#define maxm maxn*maxn#define lson(x) (splay[x].son[0])#define rson(x) (splay[x].son[1])int sum[maxn][maxn];int dp[maxn][maxn],A[maxn];int main(){ int T,i,j,k,n,o=0; scanf("%d",&T); while(T--) { scanf("%d",&n); rfor(i,1,n) scanf("%d",&A[i]); rfor(i,1,n) rfor(j,i,n) if(i==j) sum[i][j]=A[j]; else sum[i][j]=sum[i][j-1]+A[j]; mem(dp,0); rfor(i,1,n) rfor(j,i+1,n) dp[i][j]=inf; rfor(i,2,n) { //printf("%d:\n",i); for(j=1;j+i-1<=n;++j) { int l=j,r=j+i-1; for(k=1;k<=r-l+1;++k) { dp[l][r]=min(dp[l][r],dp[l+1][l+k-1]+dp[l+k][r]+k*(sum[l+k][r])+A[l]*(k-1)); } //printf("%d %d %d\n",l,r,dp[l][r]); } } printf("Case #%d: ",++o); printf("%d\n",dp[1][n]); } return 0;}
0 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)
- 如何使用lua完成复杂AI
- 简单密码
- java解惑--谜题15:令人晕头转向的Hello
- Android IPC机制(四)用ContentProvider进行进程间通信
- HTML 5 与HTML 4 的区别 + HTML5 语义化布局(一)
- HDU4283:You Are the One(区间DP)
- javase mybatis的操作数据库
- 设计模式之装饰模式
- Crash原因捕捉利器
- iOS 获取 cookie webView中使用Cookie
- Unity手游:自动寻路Navmesh入门
- linux 下查看机器是cpu是几核的
- Github提交代码方法
- oracle user_tab_partitions中,num_rows为空的处理办法