hdu1176(动态规划)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1176

题目大意:一个人站在一个0-10数轴上的5位置,天上会掉下馅饼,他要去拣,他每秒只能捡一个在那个位置的馅饼。

   例如:一开始在5位置,就可以在下一秒捡到4,5,6位置。

数塔类,简单水题。

#include <iostream>
#include <cstring>
#define clean(i) memset(i,0,sizeof(i))
using namespace std;	
int n,t,m,a[100005][12],maxx=0;
int main()
{
	while(~scanf("%d",&n) &&n)
	{
		maxx=0;
		clean(a);
		for(int i=0;i<n;i++)
		{
			scanf("%d%d",&m,&t);
			a[t][m]++;
			if(t>maxx)
				maxx=t;
		}	
		for(int i=maxx-1;i>=0;i--)
		{
			a[i][0]+=max(a[i+1][0],a[i+1][1]);
			for(int j=1;j<11;j++)
				a[i][j]+=max(max(a[i+1][j+1],a[i+1][j-1]),a[i+1][j]);
		}
		printf("%d\n",a[0][5]);
	}
	return 0;
}

猜你喜欢

转载自blog.csdn.net/ygl_6saltfish/article/details/79565070