【HDU1176】免费馅饼(记忆化搜索)

记录一个菜逼的成长。。

题目链接

简单的记忆化搜索。

#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
typedef long long LL;
#define ALL(v) (v).begin(),(v).end()
#define cl(a,b) memset(a,b,sizeof(a))
const int INF = 0x7fffffff;
const int maxn = 100000 + 10;
int dp[maxn][12],a[maxn][12],mx;
int dfs(int T,int x)
{
    if(x < 0 || x > 10)return 0;
    if(dp[T][x] != -1)return dp[T][x];
    if(T > mx)return 0;
    int ret = 0;
    for( int i = -1; i <= 1; i++ )
        ret = max(ret,dfs(T+1,x+i));
    return dp[T][x] = ret + a[T][x];
}
int main()
{
    int n;
    while(~scanf("%d",&n),n){
        cl(a,0);cl(dp,-1);
        mx = 0;
        for( int i = 0; i < n; i++ ){
            int x,T;scanf("%d%d",&x,&T);
            a[T][x] ++;
            mx = max(mx,T);
        }
        printf("%d\n",dfs(0,5));
    }
    return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值