HDU 1176 免费馅饼

传送门

#include<iostream>
#include<algorithm>
#include<map>
#include<set>
#include<vector>
#include<utility>
#include<list>
#include<deque>
#include<queue>
#include<stack>
#include<string>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<cctype>
using namespace std;
 
typedef long long LL;           //数据太大了记得用LL,还有把INF也得换
typedef pair<LL, LL> P;
 
const int maxn = 1e7+10;        //cf数组最多差不多是这么多,1e8就会段错误
const int V_MAX = 800 + 10;
const int mod = 10007;
const int INF = 0x3f3f3f3f;     //如果数据范围为long long,记得把INF的值换了
const double eps = 1e-6;        //eps开太小二分容易死循环,所以直接来个100次循环就好了


                                //多组输入时,maxn太大,用memset()会超时,血的教训;

int n;
int dp[100010][20];
int cnt[100010][20];

void solve() {
    memset(cnt, 0, sizeof cnt);
    int T = 0;
    for(int i = 1; i <= n; i++) {
        int pos, t;
        cin >> pos >> t;
        cnt[t][pos]++;
        if(t > T) T = t;
    }
    for(int i = 0; i <= T; i++) {
        for(int j = 0; j <= 10; j++) {
            dp[i][j] = -INF;
        }
    }
    dp[0][5] = 0;
    for(int i = 1; i <= T; i++) {
        for(int j = 0; j <= 10; j++) {
            if(j == 0) dp[i][j] = max(dp[i-1][j], dp[i-1][j+1]) + cnt[i][j];
            else if(j == 10) dp[i][j] = max(dp[i-1][j], dp[i-1][j-1]) + cnt[i][j];
            else dp[i][j] = max(dp[i-1][j], max(dp[i-1][j-1], dp[i-1][j+1])) + cnt[i][j];
        }
    }
    int ans = 0;
    for(int i = 0; i <= 10; i++) {
        ans = max(dp[T][i], ans);
    }
    cout << ans << endl;
}


int main()
{
    ios::sync_with_stdio(false);           //关了流同步就别用c的输入
    //freopen("D:\\in.txt", "r", stdin);
    while(cin >> n && n) { 
        solve();
    }
    return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值