跳到正文

题解

P14524 [BYOI R1] 意识解离 题解

Ryc12345678910约 2 分钟
原文
文章信息与版本

文章信息

发布
2026年10月12日
收录
2026年10月12日
更新
2026年11月7日
篇幅
约 2 分钟

版本

  1. v1当前

P14524 [BYOI R1] 意识解离 题解

题意

给出一个非负整数序列 aa,判断其能否被拆分成若干个正整数序列之和的形式,要求每个正整数序列单调不增且相加时靠右对齐。

题解

考虑简单构造一下。设 cnticnt_i 表示前 ii 个数至少要拆分成的段数。显然当 cnti>aicnt_i > a_i 时,就不存在合法的构造方案了,然后当 cnti<aicnt_i<a_i 的时候,你直接构造一个第一项为 ai−cntia_i - cnt_i 后面的均为 11 的序列与 aa 相加。

Code

C++
#include <bits/stdc++.h>
#define IOS ios::sync_with_stdio(false), cin.tie(0), cout.tie(0)
using namespace std;

namespace Lemon {
    inline void solve() {
        int n; cin >> n;
        vector<int> a(n + 1, 0);
        int d = 0;
        bool f = 0;
        for (int i = 1; i <= n; i++) {
            cin >> a[i];
            if (a[i] == 0) f = 1;
            if (a[i] > a[i - 1]) d++;
            if (a[i] < d) f = 1;
        }
        cout << (f ? "No" : "Yes") << '\n';
    }
}
signed main() {
    IOS;
    int t = 1;
    cin >> t;
    while (t--) Lemon::solve();
    return 0;
}
原文