记录编号 201954 评测结果 AAAAAAAAAA
题目名称 [SYOI 2015] Asm.Def的枪榴弹 最终得分 100
用户昵称 Gravatarcstdio 是否通过 通过
代码语言 C++ 运行时间 0.119 s
提交时间 2015-10-31 15:56:11 内存使用 30.31 MiB
显示代码纯文本
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
using namespace std;
const int SIZEN=20;
int N;
//AB:??????
//CDE:???
//??he,??heat,??emp
int A[SIZEN],B[SIZEN],C[SIZEN],D[SIZEN],E[SIZEN];
int K0,K1,K2;
int hesum=0;//??????
bool open(int x,int he,int heat,int emp,int &he1,int &heat1,int &emp1){//??+??
	//?A[x]????,B[x]???,???????he,heat,emp
	emp1=emp;
	if(he<A[x]){//?????emp????
		he1=0;
		emp1-=(A[x]-he);
	}
	else he1=he-A[x];
	if(heat<B[x]){//?????emp???
		heat1=0;
		emp1-=(B[x]-heat);
	}
	else heat1=heat-B[x];
	if(emp1<0) return false;
	he1+=C[x],heat1+=D[x],emp1+=E[x];
	return true;
}
class TG{//????
public:
	int he,heat,emp;
	TG(){he=heat=emp=-1;}
	bool avail(void){return he>-1&&heat>-1&&emp>-1;}
	int sum(void){return he+heat+emp;}
};
void update(TG &a,TG b){
	if(b.emp>a.emp) a=b;
}
bool open(int x,TG k1,TG &k2){
	return open(x,k1.he,k1.heat,k1.emp,k2.he,k2.heat,k2.emp);
}
TG f[1<<14][160];//f[s][he]:?????s,??he????
void work(void){
	int high=1<<N;
	f[0][K0].he=K0,f[0][K0].heat=K1,f[0][K0].emp=K2;
	int ans=K0+K1+K2;
	TG temp;
	for(int s=0;s<high;s++){
		for(int i=0;i<=hesum;i++){
		if(!f[s][i].avail()) continue;
			ans=max(ans,f[s][i].sum());
			for(int t=0;t<N;t++){
				if((s>>t)&1) continue;
				if(open(t,f[s][i],temp)){
					update(f[s|(1<<t)][temp.he],temp);
				}
			}
		}
	}
	printf("%d\n",ans);
}
void read(void){
	scanf("%d",&N);
	for(int i=0;i<N;i++) scanf("%d",&A[i]);
	for(int i=0;i<N;i++) scanf("%d",&B[i]);
	for(int i=0;i<N;i++) scanf("%d",&C[i]),hesum+=C[i];
	for(int i=0;i<N;i++) scanf("%d",&D[i]);
	for(int i=0;i<N;i++) scanf("%d",&E[i]);
	scanf("%d%d%d",&K0,&K1,&K2);hesum+=K0;
}
int main(){
	freopen("asm_grenade.in","r",stdin);
	freopen("asm_grenade.out","w",stdout);
	read();
	work();
	return 0;
}