题解
题目大意 给你一个长度为n的数字串 问是否能拆分成若干连续的串 每段的每位数字相加和相等
暴力枚举相加和 判断是否满足 最开始以为给的数字没有判断为00的情况
AC代码
#include <stdio.h>
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int INF = 0x3f3f3f3f;
const int MAXN = 110;
char s[MAXN];
int main()
{
#ifdef LOCAL
//freopen("C:/input.txt", "r", stdin);
#endif
int n;
cin >> n;
scanf("%s", s);
int mx = 0;
for (int i = 0; i < n; i++)
mx += s[i] - '0';
if (mx == 0) //0特判
cout << "YES" << endl, exit(0);
for (int i = 1; i < mx; i++)
{
int j = 0, tot = 0;
for (j = 0; j < n; j++)
{
tot += s[j] - '0';
if (tot == i)
tot = 0;
else if (tot > i)
break;
}
if (j == n && !tot)
cout << "YES" << endl, exit(0);
}
cout << "NO" << endl;
return 0;
}
本文探讨了一个有趣的问题:如何判断一个给定的数字串是否能够被分割成若干个连续的子串,使得每个子串中所有数字之和相等。通过详细的代码解析,展示了如何使用C++来解决这一问题,包括特判情况的处理和有效的枚举策略。
455

被折叠的 条评论
为什么被折叠?



