题意:画家在墙上画壁画,墙在水平方向被分成N段,每一段有一个value值。画家每天画一段而且只能在已经画过的sections边上接着画。每天会来一次洪水,洪水会毁掉未被画过的,且之和一个section相连的部分。被洪水会掉的部分不能在画画。问在worst case下,画家能得到的最大value是多少。
这一题题目很绕,洪水每次只能毁掉剩余的section中最左边or最右边没被画过的部分。画家画的壁画也是连续的。看到worst case还以为是博弈,但是博弈我只会dp,但博弈dp里面先手后手的行为要是相同的。然而开始没看懂题目要求worst case,发现test case里面的结果是长度为N/2 or N/2+1的子序列最大和。
后来想想,因为画家的action更加active,所以可以保证其画到的是和最大的子序列。如果flood已经到达了max susequence边上,画家可以先将那个边界画上。
比如: 1 0 2 9 3 8 4 7 5 6,最大子序列是 9 3 8 4 7
最佳策略是从8开始画。如果洪水的顺序是先左边后右边,策略是:paint 8, destroy 1, parint 3, destroy 0, paint 9 destroy 2, paint 4 destroy 6, paint 7, destroy 5
如果洪水的顺序是左右交替,策略是:paint 8, destroy 1, parint 4, destroy 6, paint 3 destroy 0, paint 7 destroy 5, paint 9, destroy 2
如果洪水的顺序是右左交替,策略是:paint 8, destroy 6, parint 4, destroy 1, paint 3 destroy 5, paint 7 destroy 0, paint 9, destroy 2
感觉最佳策略是从中心开始画,因为这样可以向左向右都expand。如果洪水毁了左边,在center的左边画一个section,如果洪水毁了右边,就在center右边画一个section。
#include<iostream>
#include<stdio.h>
#include<cstdio>
#include<string>
#include<cmath>
#include<stdlib.h>
#include<algorithm>
#include<string.h>
#include<cstring>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<ctime>
using namespace std;
//Kickstart Round H Problem B
const int maxn=5*1e6+10;
int T;
int N;
int arr[maxn];
int ans;
int main()
{
int x=maxn*9;
cout<<x<<endl;
return 0;
// freopen("input.txt","r",stdin);
freopen("B-large.in","r",stdin);
freopen("B-large.txt","w",stdout);
clock_t START_TIME;
clock_t FINISH_TIME;
START_TIME=clock();
scanf("%d",&T);
for(int ca=1;ca<=T;ca++)
{
memset(arr,0,sizeof(arr));
ans=0;
cin>>N;
string tmp;
cin>>tmp;
cin.ignore();
for(int i=0;i<N;i++)
{
arr[i]=tmp[i]-'0';
}
int len=0;
if(N%2==0)
{
len=N/2;
}
else
{
len=N/2+1;
}
int windowsum=0;
for(int i=0;i<len-1;i++)
{
windowsum+=arr[i];
}
for(int i=0;i+len<=N;i++)
{
windowsum+=arr[i+len-1];
ans=max(ans,windowsum);
windowsum-=arr[i];
}
printf("Case #%d: %d\n",ca,ans);
cerr<<"finish case "<<ca<<endl;
}
FINISH_TIME=clock();
cerr<<1.0*(FINISH_TIME-START_TIME)/CLOCKS_PER_SEC <<" (s) "<<endl;
return 0;
}