比赛 |
夭寿的小练习 |
评测结果 |
AAAAAA |
题目名称 |
免费馅饼 |
最终得分 |
100 |
用户昵称 |
Mealy |
运行时间 |
0.002 s |
代码语言 |
C++ |
内存使用 |
0.71 MiB |
提交时间 |
2016-10-19 09:28:14 |
显示代码纯文本
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
const int nmax=186;
const int INF=1<<29;
int width,height;
int sumtime=0;
int maxval=0;
int maxpos=0;
int maxtime=0;
int cnt=0;
int tmptime,tmppos,tmpvel,tmpval;
int f[nmax][nmax]={0},s[nmax][nmax]={0};
int sp[nmax][nmax]={0};
int path[nmax]={0};
void PreDo()
{
memset(s,0,sizeof(s));
scanf("%d%d",&width,&height);
while(scanf("%d%d%d%d",&tmptime,&tmppos,&tmpvel,&tmpval)!=EOF)
{
// printf("%d\n",sumtime);
if(((height-1)%tmpvel==0)||(tmptime==0))
{
s[tmptime+(height-1)/tmpvel][tmppos]+=tmpval;
if(tmptime+(height-1)/tmpvel>sumtime)
{
sumtime=tmptime+(height-1)/tmpvel;
}
}
}
// printf("sumtime:%d\n",sumtime);
}
void Init()
{
for(int i=0;i<=sumtime;i++)
{
for(int j=1;j<=width;j++)
{
f[i][j]=-INF;
}
}
// printf("%d\n\n",s[0][(width+1)]/2);
//afraid of time 0
maxval=s[0][(width+1)/2];;
f[0][(width+1)/2]=s[0][(width+1)/2];
// printf("%d\n",s[0][(width+1)/2]);
}
void Out(int tt,int tp)
{
if(tt<=0)
{
return;
}
int tmp=sp[tt][tp];
path[++cnt]=tmp;
Out(tt-1,tp-tmp);
}
void DP()
{
for(int i=1;i<=sumtime;i++)
{
for(int j=1;j<=width;j++)
{
for(int move=2;move>=-2;move--)
{
if((j-move>0)&&(j-move<=width))
{
if(f[i-1][j-move]>f[i][j])
{
f[i][j]=f[i-1][j-move];
sp[i][j]=move;
}
}
}
f[i][j]+=s[i][j];
if(f[i][j]>maxval)
{
maxval=f[i][j];
maxtime=i;
maxpos=j;
}
}
}
printf("%d\n",maxval);
if(sumtime==0&&maxval)
{
printf("0\n");
}
else
{
Out(maxtime,maxpos);
for(int i=cnt;i>=1;i--)
{
printf("%d\n",path[i]);
}
}
}
int main()
{
freopen("freepizza.in","r",stdin);
freopen("freepizza.out","w",stdout);
PreDo();
Init();
DP();
return 0;
}