CF1030C

题意:

给你一个数字,问能否拆分成k段,使得每一段的每一位数字相加结果相等。

解法:

考虑数位DP。

暴力按位考虑每一位是否满足条件

CODE:

#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream> using namespace std; int n,sum;
char s[105];
int num[105]; int main() {
scanf("%d",&n);
scanf("%s",s+1);
for(int i = 1 ; i <= n ; i++) {
sum += (int)s[i] - '0';
num[i] = (int)s[i] - '0';
}
if(sum == 0) {
puts("YES");
return 0;
}
for(int i = 1 ; i <= sum ; i++) {
int now = 0 , zz = 1 , ds = 1;
while(now < i && zz <= n) {
now += num[zz];
if(now > i) break;
if(zz == n) {
if(ds >= 3 && now == 0) {
puts("YES");
return 0;
}
}
if(now == i) {
if(ds != 1 && zz == n) {
puts("YES");
return 0;
}
ds++;
now = 0;
}
zz++;
}
}
printf("NO\n");
return 0;
}

CF1030C的更多相关文章

随机推荐

  1. es和redis cluster高可用扩容等等

    https://www.jianshu.com/p/ec465da21b4a https://www.cnblogs.com/hello-shf/p/11543468.html https://www ...

  2. [Vuex系列] - 细说state的几种用法

    state 存放的是一个对象,存放了全部的应用层级的状态,主要是存放我们日常使用的组件之间传递的变量. 我们今天重点讲解下state的几种用法,至于如何从头开始创建Vuex项目,请看我写的第一个文章. ...

  3. HighChart 不同颜色(柱状图)

    var chart = new Highcharts.Chart({ chart: { plotBackgroundColor: null, plotBorderWidth: null, backgr ...

  4. Delphi 安装apk

    procedure ToInstallApk(filename: string); var aFile: Jfile; Intent: JIntent; begin Try aFile := TJfi ...

  5. [基础累积] C#计算时间差

    TimeSpan nowTime = new TimeSpan(DateTime.Now.Ticks); TimeSpan nextTime = new TimeSpan(nextDispatcher ...

  6. Vue获取数据渲染完成事件

    主要代码是这两坨 this.nextTick(function(){ alert('数据已经更新') }); this.$nextTick(function(){ alert('v-for渲染已经完成 ...

  7. 5.Hbase API 操作开发

    Hbase API 操作开发需要连接Zookeeper进行节点的管理控制 1.配置 HBaseConfiguration: 包:org.apache.hadoop.hbase.HBaseConfigu ...

  8. tp5.1动态获取器 增加一个不存在的字段

    $list = $this->agent->where($where) ->withAttr('region',function ($value,$data){ $provice_n ...

  9. B-Tree目录和Hash索引的区别

    Hash 索引结构的特殊性,其检索效率非常高,索引的检索可以一次定位,不像B-Tree 索引需要从根节点到枝节点,最后才能访问到页节点这样多次的IO访问,所以 Hash 索引的查询效率要远高于 B-T ...

  10. Nginx的简单了解与使用

    一.产生背景 我们日常生活中经常遇到的问题 这是几年前的12306,现在的12306基本上不会出现这样的问题了 上述场景产生的主要 2 大原因:1.巨大流量2.单台服务器资源和能力有限在海量并发的环境 ...