您的位置:首页 > 其它

hdoj1176_免费馅饼(dp)

2015-06-03 18:06 441 查看
思路:从后向前更新

#include<iostream>
#include<vector>
#include<cstdio>
#include<algorithm>
#include<string.h>
using namespace std;

int map[100010][11];
int solve(int maxtime)
{
int res[11], tres[11];
memset(tres, 0, sizeof(tres));
for (int i = maxtime; i >= 0; i--)
{
for (int j = 1; j < 10; j++)
{
int t = max(tres[j - 1], tres[j+1]);
t = max(t, tres[j]);
res[j] = t + map[i][j];
}
res[0] = max(tres[0], tres[1]) + map[i][0];
res[10] = max(tres[9], tres[10]) + map[i][10];
for (int i = 0; i < 11; i++)
tres[i] = res[i];
}
return res[5];
}

int main()
{
int n;
while (scanf("%d", &n) && n)
{
memset(map, 0, sizeof(map));
int maxtime = 0;
for (int i = 0; i < n; i++)
{
int x, t;
cin >> x >> t;
map[t][x]++;
maxtime = max(maxtime, t);
}
printf("%d\n", solve(maxtime));
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: