设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 = 1000 + 10; 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, 1, x) printf("%d %d\n", ans[i].x, ans[i].y);
} void dfs(int x, int step){ if (flag) return;
if (x == n + 1){
flag = true;
print(step - 1);
return;
} dec(i, n, x) if (s[x][i]){
ans[step].x = x, ans[step].y = i;
dfs(i + 1, step + 1);
}
} int main(){ scanf("%d", &n);
rep(i, 1, n) scanf("%d", a + i);
rep(i, 1, n){
sum = 0;
rep(j, i, n){
sum += a[j];
s[i][j] = sum;
}
} dfs(1, 1);
if (!flag) puts("NO"); return 0; }

Codeforces 754A(搜索)的更多相关文章

  1. 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,所以按照题意暴力即可. #includ ...

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

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

  3. 【codeforces 754A】Lesha and array splitting

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

  4. CodeForces 164A Variable, or There and Back Again 搜索

    Variable, or There and Back Again 题目连接: http://codeforces.com/problemset/problem/164/A Description L ...

  5. CodeForces 173C Spiral Maximum 记忆化搜索 滚动数组优化

    Spiral Maximum 题目连接: http://codeforces.com/problemset/problem/173/C Description Let's consider a k × ...

  6. Codeforces Gym 100231G Voracious Steve 记忆化搜索

    Voracious Steve 题目连接: http://codeforces.com/gym/100231/attachments Description 有两个人在玩一个游戏 有一个盆子里面有n个 ...

  7. Codeforces Round #336 (Div. 2) D. Zuma 记忆化搜索

    D. Zuma 题目连接: http://www.codeforces.com/contest/608/problem/D Description Genos recently installed t ...

  8. Educational Codeforces Round 1 E. Chocolate Bar 记忆化搜索

    E. Chocolate Bar Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/598/prob ...

  9. 【搜索】【并查集】Codeforces 691D Swaps in Permutation

    题目链接: http://codeforces.com/problemset/problem/691/D 题目大意: 给一个1到N的排列,M个操作(1<=N,M<=106),每个操作可以交 ...

随机推荐

  1. 动态规划:HDU1160-FatMouse's Speed(记录动态规划状态转移过程)

    FatMouse's Speed Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) ...

  2. Android通过AIDL和反射调用系统拨打电话和挂断电话

    首先在项目中添加ITelephony.aidl文件,我的如下: /* * Copyright (C) 2007 The Android Open Source Project * * Licensed ...

  3. 15,scrapy中selenium的应用

    引入 在通过scrapy框架进行某些网站数据爬取的时候,往往会碰到页面动态数据加载的情况发生如果直接用scrapy对其url发请求,是获取不到那部分动态加载出来的数据值,但是通过观察会发现,通过浏览器 ...

  4. day15 CSS JS DOM初探

    居中  line-hight  是上下          text-line  是左右    实现一个返回顶部的功能: 1 先写好CSS 2 写动作JS 写一个悬浮菜单: <!DOCTYPE h ...

  5. IOS开发学习笔记014-ARC机制

    ARC 1.ARC机制 2.ARC 判断准则 3.注意事项 4.ARC和非ARC混合使用 ARC机制 ARC 是编译器特性,而不是 iOS 运行时特性,它也不是类似于其它语言中的垃圾收集器.因此 AR ...

  6. [netty4][netty-transpot]Channel体系分析

    Channel体系分析 接口与类结构体系 -- [I]AttributeMap, ChannelOutboundInvoker, Comparable -- [I]AttributeMap ---- ...

  7. Python中的Json模块dumps、loads、dump、load函数介绍

    Json模块dumps.loads.dump.load函数介绍 1.json.dumps() json.dumps() 用于将dict类型的数据转成str,因为如果直接将dict类型的数据写入json ...

  8. CentOS7安装Code::Blocks

    在CentOS7上安装Codelocks的过程. 1.安装gcc,需要c和c++两部分,默认安装下,CentOS不安装编译器的,在终端输入以下命令即可yum install gccyum instal ...

  9. java课堂 笔记

  10. 导入goshop2(复制自己看)

    1.goshop2采用了分布式的架构,很好的使用dubbo集成了服务.导入goshop2需要注意的事项如下: 1.1基本模块的架构: goshop-common开头的为项目的通用配置 goshop-s ...