HDU-4823 You Are the One

原创 2018年04月15日 17:33:32

区间DP,有n个屌丝要出场,每个屌丝有个屌丝值a[i],他们最终屌丝值为(k-1)*a[i],(k为出场次序)
屌丝是按顺序站好的,而且要按顺序出场,有一个栈堆可以暂时让屌丝进去以改变出场顺序
问这样所有屌丝的总屌丝值最少是多少
用d[l][r][k]存储最少值,l~r区间,k为0代表在队伍中,k为1代表已经入栈(不可颠倒)
状态转移为: 
if(k) //已经入栈
  {
   d[l][r][k]=min(d[l][r][k],dp(l,i,1)+dp(i+1,r,1)+(sum[i]-sum[l-1])*(r-i)); 
  } //sum[i]为前i个屌丝屌丝值总和
  else //还未入栈
  {
   d[l][r][k]=min(d[l][r][k],dp(l,i,k)+dp(i+1,r,k)+(sum[r]-sum[i])*(i-l+1));
   d[l][r][k]=min(d[l][r][k],dp(l,i,1)+dp(i+1,r,k)+(sum[i]-sum[l-1])*(r-i));
  }  
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<stack>
using namespace std;
const int N=100+10;
const int INF=0x7f7f7f7f;
int a[N],sum[N];
int d[N][N][2];
int n;
int dp(int l,int r,int k)
{
	if(l==r) return 0;
	if(d[l][r][k]!=-1) return d[l][r][k];
	d[l][r][k]=INF;
	for(int i=l;i<r;i++)
	{
		if(k) //已经入栈
		{
			d[l][r][k]=min(d[l][r][k],dp(l,i,1)+dp(i+1,r,1)+(sum[i]-sum[l-1])*(r-i));
		}
		else //还未入栈
		{
			d[l][r][k]=min(d[l][r][k],dp(l,i,k)+dp(i+1,r,k)+(sum[r]-sum[i])*(i-l+1));
			d[l][r][k]=min(d[l][r][k],dp(l,i,1)+dp(i+1,r,k)+(sum[i]-sum[l-1])*(r-i));
		}	
	}
	return d[l][r][k];
}
int main()
{
	int T,kase=0;
	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(d,-1,sizeof(d));
		printf("Case #%d: %d\n",++kase,dp(1,n,0));
	}	
	return 0;
}

hdu4283---You Are the One(区间dp)

Problem Description   The TV shows such as You Are the One has been very popular. In order to meet ...
  • Guard_Mine
  • Guard_Mine
  • 2015-02-23 15:03:36
  • 728

Access denied; you need (at least one of) the RELOAD privilege(s) for this operation

1. reload 是 administrative 级的权限,即 server administration;这类权限包括: CREATE USER, PROCESS, RELOAD, REP...
  • ljasdf123
  • ljasdf123
  • 2014-06-13 17:15:05
  • 24142

ERROR 1227 (42000): Access denied; you need (at least one of) the PROCESS privilege(s) for this oper

1  用以往的mysql登陆模式登陆 [mysql@eanintmydbc002db1 mysqllog]$ mysql  Enter password:  Welcome to the MySQL ...
  • mchdba
  • mchdba
  • 2013-08-29 10:12:52
  • 11077

Mac 下的MySQL ERROR 1227(42000): Access denied; you need (at least one of)

原文:http://blog.itpub.net/27099995/viewspace-1148875/ Mac 下的MySQL(只有连个库) AC-IT002deMacBook-Pr...
  • chenhualeguan
  • chenhualeguan
  • 2016-07-05 15:57:10
  • 4696

more than one `-Acdtrux' or `--test-label' option

在Linux上解压文件时通过命令 tar -xzvf ql.tar.gz -c app/ 出现了 tar: You may not specify more than one -Acdtrux' ...
  • qq_33101355
  • qq_33101355
  • 2017-06-03 12:54:55
  • 3172

Android studio 3.0 Warning:One of the plugins you are using supports Java 8 language features. To t

Warning:One of the plugins you are using supports Java 8 language features. To try the support built...
  • bobby_fu
  • bobby_fu
  • 2018-01-19 15:08:59
  • 650

cxf 发布webservice报 You have more than one version of 'org.apache.commons.logging.Log' visible

 项目中采用cxf发布webservice,在同一osgi环境下写测试类发现能够正常运行,但经过发布成webservice后,用工程调用报如下异常: org.apache.commons.loggin...
  • einarzhang
  • einarzhang
  • 2011-02-13 12:38:00
  • 3721

2017年上海金马五校程序设计竞赛:Problem G : One for You

Problem G : One for You From: DHUOJ, 2017060307 Submit (Out of Contest) Time Limit: 1 s D...
  • wyxeainn
  • wyxeainn
  • 2017-06-03 19:57:56
  • 552

Error creating assembly archive pack: You must set at least one file.

今天用maven的assembly插件打包,发现了一个bug,打包后会报下面的错: Error creating assembly archive pack: You must set at le...
  • liuxiao723846
  • liuxiao723846
  • 2016-11-15 15:43:50
  • 2236
收藏助手
不良信息举报
您举报文章:HDU-4823 You Are the One
举报原因:
原因补充:

(最多只允许输入30个字)