cf#512 C. Vasya and Golden Ticket

题目链接 http://codeforces.com/contest/1058/problem/C

这题还是暴力最方便,和的情况最多有n*a[i]  900种把每种都试一遍

 1 #include<bits/stdc++.h>
 2 using namespace std;
 3 int n;
 4 string s;
 5 bool check(int x)
 6 {
 7 
 8     int sum=0,cnt=0;
 9     for(int i=0;i<n;i++)
10     {
11         sum+=(s[i]-'0');
12         if(sum==x)
13         {
14 
15             sum=0;cnt++;
16         }
17         else if(sum>x)
18         {
19 
20             return false;
21         }
22     }
23     if(sum!=0)return false;
24     if(cnt>=2)return true;
25     else return false;
26 }
27 int main()
28 {
29     cin>>n>>s;
30     int num=n*9;
31     for(int i=0;i<=num;i++)
32     {
33         if(check(i))
34         {
35             cout<<"YES"<<endl;
36             return 0;
37         }
38     }
39     cout<<"NO"<<endl;
40     return 0;
41 }
原文地址:https://www.cnblogs.com/fqfzs/p/9750799.html