P14524 [BYOI R1] 意识解离 题解
题意
给出一个非负整数序列 ,判断其能否被拆分成若干个正整数序列之和的形式,要求每个正整数序列单调不增且相加时靠右对齐。
题解
考虑简单构造一下。设 表示前 个数至少要拆分成的段数。显然当 时,就不存在合法的构造方案了,然后当 的时候,你直接构造一个第一项为 后面的均为 的序列与 相加。
Code
#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;
}