比赛 20140423 评测结果 AAWAWAWWWW
题目名称 电子书狂热者 最终得分 40
用户昵称 cstdio 运行时间 1.741 s
代码语言 C++ 内存使用 0.45 MiB
提交时间 2014-04-23 10:37:05
显示代码纯文本
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<vector>
#include<queue>
using namespace std;
typedef long long ll;
const int SIZEN=1010,SIZES=10010;
const ll INF=1e15;
int N;
ll booknum[SIZEN];
ll readsum[SIZEN];
ll price[SIZEN];
int n2;//第一种套餐
ll A[SIZEN],R[SIZEN];
//连续A[i]本交R[i]
ll booksum;//读书总数
ll conw[SIZES]={0};
int n3;//第二种套餐
ll B[SIZEN],S[SIZEN];
//连续B[i]天交S[i]
ll f[SIZEN];
void preDP(void){
	for(int i=0;i<=booksum;i++) conw[i]=INF;
	//cout<<conw[booksum]<<endl;
	conw[0]=0;
	for(int i=1;i<=n2;i++){
		//这个套餐:连续A[i]本交R[i]
		//cout<<A[i]<<" "<<R[i]<<endl;
		for(int j=A[i];j>=0;j--) conw[j]=min(conw[j],R[i]);
		//for(int j=A[i];j<=booksum;j++) conw[j]=min(conw[j],conw[j-A[i]]+R[i]);
	}
	//for(int i=1;i<=booksum;i++){cout<<conw[i]<<" ";}cout<<endl;
	for(int i=1;i<=booksum;i++){
		for(int j=1;j*2<=i;j++){
			conw[i]=min(conw[i],conw[j]+conw[i-j]);
		}
	}
	//for(int i=booksum-1;i>=0;i--) conw[i]=min(conw[i],conw[i+1]);//可以以多付少
	//for(int i=0;i<=booksum;i++){cout<<conw[i]<<" ";cout<<endl;}
}
void work(void){
	f[0]=0;
	for(int i=1;i<=N;i++){
		//cout<<f[i-1]<<" "<<booknum[i]<<" "<<price[i]<<endl;
		f[i]=f[i-1]+booknum[i]*price[i];
		//cout<<f[i]<<endl;
		for(int j=0;j<i;j++) f[i]=min(f[i],f[j]+conw[readsum[i]-readsum[j]]);//最后用了若干次第一种套餐,j是上一个"完整的天"
		for(int j=1;j<=n3;j++) f[i]=min(f[i],f[i-B[j]]+S[j]);//最后用了第二种套餐,j是用的套餐编号
		//这个套餐是连续B[j]天交S[j]
		//cout<<f[i]<<endl;
	}
	printf("%lld\n",f[N]);
}
bool read(void){
	scanf("%d",&N);
	if(!N) return false;
	memset(booknum,0,sizeof(booknum));
	memset(readsum,0,sizeof(readsum));
	memset(price,0,sizeof(price));
	memset(A,0,sizeof(A));
	memset(R,0,sizeof(R));
	memset(conw,0,sizeof(conw));
	memset(B,0,sizeof(B));
	memset(S,0,sizeof(S));
	memset(f,0,sizeof(f));
	booksum=0;
	readsum[0]=0;
	for(int i=1;i<=N;i++) scanf("%lld",&booknum[i]),booksum+=booknum[i],readsum[i]=readsum[i-1]+booknum[i];
	int n1;
	scanf("%d",&n1);
	int last=0,c;
	ll p;
	for(int i=1;i<=n1;i++){
		//scanf("%d %lld",&c,&p);
		cin>>c>>p;
		//cout<<c<<" "<<p<<endl;
		for(int j=last;j<c;j++) price[j]=price[last];
		price[c]=p;
		last=c;
	}
	for(int j=last;j<=N;j++) price[j]=price[last];
	//cout<<booksum<<endl;
	//for(int i=1;i<=N;i++) cout<<booknum[i]<<" ";cout<<endl;
	scanf("%d",&n2);
	for(int i=1;i<=n2;i++) scanf("%lld%lld",&A[i],&R[i]);
	scanf("%d",&n3);
	for(int i=1;i<=n3;i++) scanf("%lld%lld",&B[i],&S[i]);
	return true;
}
int main(){
	freopen("zealot.in","r",stdin);
	freopen("zealot.out","w",stdout);
	while(read()){
		preDP();
		work();
	}
	return 0;
}