题目链接 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 (搜索)的更多相关文章

  1. Codeforces 754A Lesha and array splitting(简单贪心)

    A. Lesha and array splitting time limit per test:2 seconds memory limit per test:256 megabytes input ...

  2. 【codeforces 754A】Lesha and array splitting

    time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...

  3. Codeforces Round #390 (Div. 2) A. Lesha and array splitting

    http://codeforces.com/contest/754/problem/A 题意: 给出一串序列,现在要把这串序列分成多个序列,使得每一个序列的sum都不为0. 思路: 先统计一下不为0的 ...

  4. cf754 A. Lesha and array splitting

    应该是做麻烦了,一开始还没A(幸好上一次比赛水惨了) #include<bits/stdc++.h> #define lowbit(x) x&(-x) #define LL lon ...

  5. Educational Codeforces Round 69 (Rated for Div. 2) C. Array Splitting 水题

    C. Array Splitting You are given a sorted array

  6. Codeforces 442C Artem and Array(stack+贪婪)

    题目连接:Codeforces 442C Artem and Array 题目大意:给出一个数组,每次删除一个数.删除一个数的得分为两边数的最小值,假设左右有一边不存在则算作0分. 问最大得分是多少. ...

  7. Codeforces Round #504 D. Array Restoration

    Codeforces Round #504 D. Array Restoration 题目描述:有一个长度为\(n\)的序列\(a\),有\(q\)次操作,第\(i\)次选择一个区间,将区间里的数全部 ...

  8. 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 ...

  9. Codeforces 754A(搜索)

    设s[i][j]为序列i到j的和,当s[i][j]≠0时,即可从i跳到j+1.目标为从1跳到n+1,所以按照题意暴力即可. #include <bits/stdc++.h> using n ...

随机推荐

  1. loj2044 「CQOI2016」手机号码

    ref #include <iostream> #include <cstring> #include <cstdio> using namespace std; ...

  2. 线段树&树状数组模板

    树状数组: #include <bits/stdc++.h> using namespace std; ; struct binit { int a[MAXN], n; void modi ...

  3. IOS开发学习笔记038-autolayout 自动布局 界面实现

    在storyboard/xib文件中实现自动布局 autolayout 1.注意事项 autolayout和frame属性是有冲突的,所以如果准备使用autolayout,就不要再代码中对控件的fra ...

  4. MFC定时关机程序的实现3-最小化到托盘栏

    这个定时关机运行过后默认最小化到托盘栏最好了,不用每次都去点了. 现在来看看如何将程序显示在托盘栏. 首先在头文件里声明一个变量和一个消息响应函数 //最小化到托盘栏 //第一步,生成一个成员变量,或 ...

  5. seajs引入jquery

    seajs 2.2.1在config文件中preload一次jquery,就可以在整个项目中使用jquery.如下: seajs.on('exec', function(module) { if (m ...

  6. Mac教程macOS教程 苹果电脑教程

    第1 章 初识MacOS 01 菜单栏 02 键盘 03 聚焦(Spotlight)

  7. CSU-1974 神奇药水

    CSU-1974 神奇药水 Description ​ 对于csuxushu来说,能够在CSU(California State University)组织2017年的ACM暑期集训让他感到十分荣幸. ...

  8. LFTP下载远程文件

    拓展阅读: https://linux.cn/article-5460-1.html

  9. layer 体验

    做后端的,前端一直不擅长,提示语以前也只会alert,非常难看,后来在别人代码看到lay.msg() https://pan.baidu.com/s/1eRHH59g <!DOCTYPE htm ...

  10. POJ 2376:Cleaning Shifts(贪心)

    题目大意:有n个奶牛,他们负责在长为t个时间点的时间内值班,每个时间点至少有一个在值班,每个奶牛有一段空闲时间可以值班,求满足要求所需最少奶牛数量,无法满足则输出-1. 分析: 将奶牛空闲时间段看成线 ...