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 ...
随机推荐
- Git-Git初始化
创建版本库及第一次提交 通过如下操作来查看一下您的Git版本. $ git --version git version 1.7.4 在开始 Git 之旅之前,我们需要设置一下 Git 的配置变量,这是 ...
- idea 安装findBugs 可以做代码扫描,也可以导出扫描结果生成扫描报告
idea 安装findBugs 可以做代码扫描,也可以导出扫描结果生成扫描报告 https://my.oschina.net/viakiba/blog/1838296 https://www.cnbl ...
- IOS开发---菜鸟学习之路--(十)-实现新闻详细信息浏览页面
前面已经将了上下拉刷新 实现了上下拉刷新后我们的第一级界面就做好,接下来我们就需要实现 新闻详细信息浏览了 我个人认为一般实现新闻详细页面的方法有两种(主要是数据源的不同导致了方法的不同) 第一种是本 ...
- 【Combinations】cpp
题目: Given two integers n and k, return all possible combinations of k numbers out of 1 ... n. For ex ...
- jmeter连接数据库之增删改查
配置jdbc: 查询sql配置: 插入sql配置: 修改sql配置: 删除sql配置:
- 聊聊、CA机构认证CSR生成
https://search.thawte.com/support/ssl-digital-certificates/index?page=content&id=SO832 https://s ...
- [c++基础]3/5原则--拷贝构造函数+拷贝赋值操作符
/* * main.cpp * * Created on: Apr 7, 2016 * Author: lizhen */ #include <iostream> #include &qu ...
- leetcode NO.349 两个数组的交集 (python实现)
来源 https://leetcode-cn.com/problems/intersection-of-two-arrays/ 题目描述 给定两个数组,写一个函数来计算它们的交集. 例子: 给定 nu ...
- MySql数据库 - 3.利用MySql Workbench 对数据库进行操作
打开MySql Workbench 选择呢一个数据库 查看数据库: 创建数据库 在SCHEMAS下的空白位置右键 - 选择 Create Schema... 如果数据库名字中有大写字母,会出现如下提示 ...
- Mysql实战之索引
author:JevonWei 版权声明:原创作品 索引基础: 索引:提取索引的创建在的表上字段中的数据,构建出一个独特的数据结构: 索引的作用:加速查询操作:副作用:降低写操作性能: 表中数据子集: ...