跳过正文
  1. Posts/

hdu 4283 You Are the One (区间dp)

·2 分钟
目录

hdu 4283题目链接

题意:有N个人按顺序排成一排上台表演,每个都有一个num[]值,若在他是第k个上场的人,则会有num[]*(k-1)的unhappiness。台下有一个黑屋(stack),对每一个人,可以选择让他先进屋子或者直接上台。现在让你找到一个最优方案使得所有人的unhappiness之和最小。

思路:

我想对了的:
#

无。状态设计就错了。。。转移方程也就不可能对。。。

错的一塌糊涂。。。嗯。。基础题。。完全不会2333

参考题解:参考博客1 参考博客2

 1/* ***********************************************
 2Author :111qqz
 3Created Time :2016年07月26日 星期二 15时03分41秒
 4File Name :code/hdu/4283.cpp
 5************************************************ */
 6
 7#include <cstdio>
 8#include <cstring>
 9#include <iostream>
10#include <algorithm>
11#include <vector>
12#include <queue>
13#include <set>
14#include <map>
15#include <string>
16#include <cmath>
17#include <cstdlib>
18#include <ctime>
19#define fst first
20#define sec second
21#define lson l,m,rt<<1
22#define rson m+1,r,rt<<1|1
23#define ms(a,x) memset(a,x,sizeof(a))
24typedef long long LL;
25#define pi pair < int ,int >
26#define MP make_pair
27
28using namespace std;
29const double eps = 1E-8;
30const int dx4[4]={1,0,0,-1};
31const int dy4[4]={0,-1,1,0};
32const int inf = 0x3f3f3f3f;
33const int N=105;
34int n;
35int a[N];
36int sum[N];
37int dp[N][N];
38int main()
39{
40	#ifndef  ONLINE_JUDGE
41	freopen("code/in.txt","r",stdin);
42  #endif
43
44	int T;
45	cin>>T;
46	int cas = 0 ;
47	while (T--)
48	{
49	    scanf("%d",&n);
50//	    cout<<"n:"<<n<<endl;
51	    sum[0] = 0 ;
52	    for ( int i = 1 ; i <= n ; i++)
53	    {
54		int x;
55		scanf("%d",&x);
56		a[i] = x;
57		sum[i] = sum[i-1] + x;
58	    }
59
60	    for ( int l = 2 ; l  <= n ; l++) //区间长度
61		for ( int  i =  1 ; i+l-1 <= n ; i++) //区间以第i人开始,以第j人结束。
62		{
63		    int j = i+l-1;dp[i][j]=inf;
64		    for ( int k = i ; k <= j ; k++ )  //第i人可能在当前区间[i,j]中是第k-i+1个出场的。。。就是说在枚举出场顺序。。
65			dp[i][j] =min(dp[i][j],dp[i+1][k]+dp[k+1][j]+(k-i)*a[i]+(k-i+1)*(sum[j]-sum[k]));
66
67	//	    cout<<"i:"<<i<<" j:"<<" dp[i][j]:"<<dp[i][j]<<endl;
68		}
69
70	     printf("Case #%d: %d\n",++cas,dp[1][n]);
71
72
73	}
74
75
76  #ifndef ONLINE_JUDGE
77  fclose(stdin);
78  #endif
79    return 0;
80}

相关文章

poj 3661 Running (区间dp)

·3 分钟
poj 3661题目链接 题意:锻炼,一共n分钟,每分钟可以选择跑步或者休息,第i分钟跑步可以跑d[i]米,并增加一点疲劳度,如果选择休息,那么每分钟减少1点疲劳值。一旦开始休息,必须休息到疲劳值为0才能再次开始跑步。疲劳值不能超过m.第n分钟的时候疲劳值必须为0,否则之后会感觉身体被掏空。问n分钟最远多多远。

light oj 1422 - Halloween Costumes (区间dp)

·2 分钟
light oj 1422 题目链接 题意: 按顺序去参加舞会。每个舞会对衣服都有要求。可以连续穿好多件衣服。需要时候就脱下来,但是一旦脱下来,这件衣服就报废了。问最少需要几件衣服。

poj 2955 Brackets(区间dp....括号匹配。。。人生第一道区间dp)

·2 分钟
poj2955题目链接 题意:给出若干括号,问最大匹配数是多少。 思路:没有思路。我知道这是dp。。。然后其他就什么都不知道了。。。转移方程? 完全没思路。。知道了转移方程。。。。嗯,还是不会。。。边界怎么写?状态怎么推?循环顺序? 循环次序?我一点思路都没有。。。。。