HDU 1176 免费馅饼 解题报告

HDU 1176 免费馅饼 解题报告

解题思路:dp题,把馅饼掉落情况看成一个二维数组dp[t][x],t表示时间,x表示位置,从底往上走就行。
思路简单,关键是模型能否分析出来。
HDU 1176 免费馅饼 解题报告

#include<iostream>
#include<math.h>
#include<iomanip>
#include<algorithm>
#include<queue>
#include<cstring>
#include<string>
#include<map>
#include<stack>
#include<stdio.h>
#include<cstdio>
#include<stdlib.h>
#include<fstream>
#include<iomanip>
#pragma warning(disable:4996)
#define INF 0x3f3f3f3f
#define ll long long
#define PI acos(-1.0)
const int N = 1000010;
const int maxn = 1e9;
using namespace std;
int dp[100005][12];

int main()
{
	int n,x,t,tm=0;
	while (scanf("%d",&n)!=EOF&&n)
	{
		memset(dp, 0, sizeof(dp));
		for (int i = 1; i <= n; i++)
		{
			scanf("%d%d", &x, &t);
			tm = max(t, tm);
			dp[t][x] += 1;
		}
		for (int i = tm-1; i >= 0; i--)
		{
			for (int j = 0; j <= 10; j++)
			{
				dp[i][j] += max(dp[i + 1][j], max(dp[i + 1][j - 1], dp[i + 1][j + 1]));
			}
		}
		printf("%d\n", dp[0][5]);
	}
}

HDU 1176 免费馅饼 解题报告HDU 1176 免费馅饼 解题报告 人见人弯加奈美 发布了14 篇原创文章 · 获赞 0 · 访问量 210 私信 关注
上一篇:hdu 1176 免费馅饼


下一篇:HDU 1176 免费馅饼