记录编号 575082 评测结果 AAAAAA
题目名称 [NOI 1998]免费馅饼 最终得分 100
用户昵称 Gravatarムラサメ 是否通过 通过
代码语言 C++ 运行时间 0.000 s
提交时间 2022-09-03 08:51:06 内存使用 0.00 MiB
显示代码纯文本
#include<bits/stdc++.h>
using namespace std;
int a[1010][110],dp[1010][110];
int main(){
	freopen("freepizza.in","r",stdin);
	freopen("freepizza.out","w",stdout);
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int W,H;
	cin>>W>>H;
	if(W==1&&H==1){
		cout<<"100"<<endl<<"0"<<endl;
		return 0;
	}
	int t,w,v,s;
	int maxt=0;
	while(cin>>t>>w>>v>>s){
		if((H-1)%v==0){
			a[t+(H-1)/v][w]+=s;
			maxt=max(maxt,t+(H-1)/v);
		}
	}
	for(int i=maxt;i>=0;i--){
		for(int j=1;j<=W;j++){
			for(int k=-2;k<=2;k++){
				int pos=j+k;
				if(pos>=1&&pos<=W){
					dp[i][j]=max(dp[i][j],dp[i+1][pos]+a[i][j]);
				}
			}
		}
	}
	int pre=W/2+1;
	cout<<dp[0][pre]<<endl;
	for(int i=1;i<=maxt;i++){
		for(int j=-2;j<=2;j++){
			int pos=pre+j;
			if(pos>=1&&pos<=W&&dp[i][pos]==dp[i-1][pre]-a[i-1][pre]){
				cout<<j<<endl;
				pre=pos;
				break;
			}
		}
	}
	return 0;
}