Codeforces 754A Lesha and array splitting (搜索)
题目链接 Lesha and array splitting
设s[i][j]为序列i到j的和,当s[i][j]≠0时,即可从i跳到j+1.目标为从1跳到n+1,所以按照题意暴力即可。
#include <bits/stdc++.h> using namespace std; #define rep(i,a,b) for(int i(a); i <= (b); ++i)
#define dec(i,a,b) for(int i(a); i >= (b); --i) const int Q = + ; struct node{
int x, y;
} ans[Q];
int s[Q][Q];
int a[Q]; bool flag = false;
int n;
int sum; void print(int x){
printf("YES\n%d\n", x);
rep(i, , x) printf("%d %d\n", ans[i].x, ans[i].y);
} void dfs(int x, int step){ if (flag) return;
if (x == n + ){
flag = true;
print(step - );
return;
} dec(i, n, x) if (s[x][i]){
ans[step].x = x, ans[step].y = i;
dfs(i + , step + );
}
} int main(){ scanf("%d", &n);
rep(i, , n) scanf("%d", a + i);
rep(i, , n){
sum = ;
rep(j, i, n){
sum += a[j];
s[i][j] = sum;
}
} dfs(, );
if (!flag) puts("NO"); return ; }
Codeforces 754A Lesha and array splitting (搜索)的更多相关文章
- Codeforces 754A Lesha and array splitting(简单贪心)
A. Lesha and array splitting time limit per test:2 seconds memory limit per test:256 megabytes input ...
- 【codeforces 754A】Lesha and array splitting
time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...
- Codeforces Round #390 (Div. 2) A. Lesha and array splitting
http://codeforces.com/contest/754/problem/A 题意: 给出一串序列,现在要把这串序列分成多个序列,使得每一个序列的sum都不为0. 思路: 先统计一下不为0的 ...
- cf754 A. Lesha and array splitting
应该是做麻烦了,一开始还没A(幸好上一次比赛水惨了) #include<bits/stdc++.h> #define lowbit(x) x&(-x) #define LL lon ...
- Educational Codeforces Round 69 (Rated for Div. 2) C. Array Splitting 水题
C. Array Splitting You are given a sorted array
- Codeforces 442C Artem and Array(stack+贪婪)
题目连接:Codeforces 442C Artem and Array 题目大意:给出一个数组,每次删除一个数.删除一个数的得分为两边数的最小值,假设左右有一边不存在则算作0分. 问最大得分是多少. ...
- Codeforces Round #504 D. Array Restoration
Codeforces Round #504 D. Array Restoration 题目描述:有一个长度为\(n\)的序列\(a\),有\(q\)次操作,第\(i\)次选择一个区间,将区间里的数全部 ...
- CodeForces - 1175D Array Splitting(数组划分+后缀和+贪心)
You are given an array a1,a2,…,ana1,a2,…,an and an integer kk. You are asked to divide this array in ...
- Codeforces 754A(搜索)
设s[i][j]为序列i到j的和,当s[i][j]≠0时,即可从i跳到j+1.目标为从1跳到n+1,所以按照题意暴力即可. #include <bits/stdc++.h> using n ...
随机推荐
- tomcat8+idea远程调试
window下 setenv.bat增加 set JPDA_OPTS=-Xrunjdwp:transport=dt_socket,address=8787,server=y,suspend=n lin ...
- J.U.C 系列之 Tools
JDK 5.0 开始,java并发大师Doug lea 为我们带来了更高效更应用的java并发API Java.util.concurrent包,简称J.U.C J.U.C 体系由如下五个知识结构构成 ...
- 「微信小程序免费辅导教程」24,基础内容组件icon的使用探索与7月26日微信公众平台的更新解读
- getsupportfragmentmanager 没有这个方法
让activity继承自fragmentactivity就行了.
- Eclipse主题更换方法
1.打开Eclipse的Help->Eclipse Marketplace 2.在Find里搜索Eclipse Color Theme,点击Install按钮 3.打开Window->Pr ...
- [网站公告]11月26日00:00-04:00阿里云RDS升级
大家好,11月26号00:00-04:00(今天夜里),阿里云将对我们所用的SQL Server RDS实例所在的物理主机做升级操作(目前博客园整站运行于阿里云上),升级期间RDS实例会有2次闪断,每 ...
- 16、响应式布局和BootStrap 全局CSS样式知识点总结-part3
1.响应式工具 ①可用的类 <div class="container"> <a href="#" class="visible-x ...
- 【3Sum Closest 】cpp
题目: Given an array S of n integers, find three integers in S such that the sum is closest to a given ...
- Anaconda的用法
1. conda list -----显示anacoda安装的模块 2.jupyter notebook----启动网页上的python编程环境 3.anacoda search -t conda ...
- 爬虫:Scrapy6 - Item Loaders
Item Loaders 提供了一种便捷的方式填充抓取到的:Items.虽然 Items 可以使用自带的类字典形式的 API 填充,但是 Item Loaders 提供了更便捷的 API,可以分析原始 ...