zoukankan      html  css  js  c++  java
  • Codeforces 754A(搜索)

    设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
    %d
    ", x);
    	rep(i, 1, x) printf("%d %d
    ", 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;
    
    }
    
    
    

  • 相关阅读:
    BigPipe
    HDFS Scribe Integration 【转】
    C++ | class size
    Leetcode | Container With Most Water
    Leetcode | Sqrt(x)
    Network | sk_buff
    JVM, JRE 和JDK
    facebook面试题【转】
    ML | SVM
    ML| EM
  • 原文地址:https://www.cnblogs.com/cxhscst2/p/6648798.html
Copyright © 2011-2022 走看看