zoukankan      html  css  js  c++  java
  • POJ 1950

    直接DFS,因为实在没想到什么剪枝了...

    注意一点是,10.11使用的是1011哦

    #include <iostream>
    #include <cstdio>
    #include <algorithm>
    #include <cmath>
    #define LL __int64
    using namespace std;
    int n,ct,k;
    char str[20];
    
    void dfs(LL sum,LL last,int pos){
    	if(pos==n+1){
    		if(sum==0){
    			ct++;
    			if(ct<=20){
    				for(int i=1;i<n;i++){
    					printf("%d %c ",i,str[i]);
    				}
    				printf("%d
    ",n);
    			}
    		}
    		return ;
    	}
    	str[pos-1]='+';
    	dfs(sum+pos,pos,pos+1);
    	str[pos-1]='-';
    	dfs(sum-pos,-pos,pos+1);
    	str[pos-1]='.';
    	if(pos>=10){
    		k=100;
    	}
    	else k=10;
    	if(last<0)
    	dfs(sum-last+last*k-pos,last*k-pos,pos+1);
    	else if(last>0){
    		dfs(sum-last+last*k+pos,last*k+pos,pos+1);
    	}
    }
    
    int main(){
    	while(scanf("%d",&n)!=EOF){
    		ct=0;
    		dfs(1,1,2);   //sum,last,pos,char
    		printf("%d
    ",ct);
    	}
    	return 0;
    }
    

      

  • 相关阅读:
    vue 之 vuex
    vue中this.$router.push() 传参
    ES6新特性
    css优先级
    创建第一个vue工程
    对Vue.js的认知
    前端的认知与见解
    Web前端常见问题
    数据库如何进行索引优化
    Python FAQ
  • 原文地址:https://www.cnblogs.com/jie-dcai/p/4290998.html
Copyright © 2011-2022 走看看