AcWing 4552. 免费馅饼

ft,x 表示,现在时间为 t,位于的位置为 x 最多可以接到的馅饼个数,可得状态转移方程:

ft,x={max{ft1,x,ft1,x1,ft1,x+1},0<x<10max{ft1,x,ft1,x+1},x=0max{ft1,x,ft1,x1},x=10

// #define FILE_INPUT
#pragma GCC optimize(2)
#pragma GCC optimize(3)
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;

#define rep(i, a, b) for (int i = a, END##i = b; i <= END##i; i++)
#define per(i, a, b) for (int i = a, END##i = b; i >= END##i; i--)

void Init();
void Solve();

signed main() {
    cin.sync_with_stdio(0);
    cin.tie(0), cout.tie(0);

    #ifdef FILE_INPUT
        freopen("input.in", "r", stdin);
    #endif

    int T = 1;
    // cin >> T;
    while (T--) {
        Init();
        Solve();
    }
    return 0;
}

using LL = long long;
using ULL = unsigned long long;

const int Mod = 1e9 + 7;
const int Inf = 0x3f3f3f3f;
const LL InfLL = 0x3f3f3f3f3f3f3f3f;

const int N = 1e5 + 10;
int n, f[N][20], c[N][20];


void Init() {
}

void Solve() {
    while (cin >> n, n) {
        memset(f, -0x3f, sizeof(f));
        memset(c, 0, sizeof(c));
        while (n--) {
            int x, t; cin >> x >> t;
            c[t][x]++;
        }
        int ans = 0;
        f[0][5] = 0;
        rep(t, 1, 1e5) {
            rep(x, 0, 10) {
                if (x == 0) f[t][x] = max(f[t - 1][x], f[t - 1][x + 1]) + c[t][x];
                else if (x == 10) f[t][x] = max(f[t - 1][x], f[t - 1][x - 1]) + c[t][x];
                else f[t][x] = max({f[t - 1][x - 1], f[t - 1][x + 1], f[t - 1][x]}) + c[t][x];
            }
        }
        rep(x, 0, 10) ans = max(ans, f[100000][x]);
        cout << ans << "\n";
    }
}
posted @   wh2011  阅读(2)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· 单线程的Redis速度为什么快?
· SQL Server 2025 AI相关能力初探
· AI编程工具终极对决:字节Trae VS Cursor,谁才是开发者新宠?
· 展开说说关于C#中ORM框架的用法!
点击右上角即可分享
微信分享提示