zoj 1711 Sum It Up //深搜
来源:互联网 发布:如何评价诗词 知乎 编辑:程序博客网 时间:2024/06/04 18:38
居然没超时 ... ps:index 是关键字么 ...
#include<iostream>#include<stdio.h>#include<string.h>#include<stdlib.h>using namespace std;int t,n,flag,ll;int a[14],vis[14];char pr[1000][100];//int f[15]={1,2,4,8,16,32,64,128,256,512,1024,2048,4096};int cmp(const void *a,const void *b){return (*(int *)a)<(*(int *)b)? 1:-1;}void pri(){int kk=0;char st[100];for(int i=0;i<n;i++)if(vis[i]){int temp=a[i];while(temp!=0){st[kk++]=temp%10-'0';temp/=10;}}st[kk++]='\0';for(int i=0;i<ll;i++)if(strcmp(st,pr[i])==0) return ;strcpy(pr[ll++],st);kk=0;for(int i=0;i<n;i++)if(vis[i]) { if(!kk) printf("%d",a[i]),kk=1;else printf("+%d",a[i]); }printf("\n");}void dfs(int sum,int k){if(sum==t){ flag=1; pri(); return ;}if(sum>t) return ;for(int i=k;i<n;i++)if(!vis[i]){vis[i]=1;dfs(sum+a[i],i+1);vis[i]=0;}}int main(){while(scanf("%d %d",&t,&n)!=EOF&&n){for(int i=0;i<n;i++)scanf("%d",&a[i]);printf("Sums of %d:\n",t);memset(vis,0,sizeof(vis));qsort(a,n,sizeof(a[0]),cmp);ll =0;flag=0;dfs(0,0);if(!flag)printf("NONE\n");}return 0;}
- zoj 1711 Sum It Up //深搜
- zoj 1711 Sum It Up
- ZOJ 1711 Sum It Up
- zoj 1711 Sum It Up
- ZOJ 1711 Sum It Up
- ZOJ 1711 Sum It Up
- ZOJ 1711 Sum It Up(DFS啊 )
- zoj 1711 || poj 1564 Sum It Up(DFS~~~去重~)
- poj1564 Sum It Up (zoj 1711 hdu 1258) DFS
- 深搜---Sum it up
- 1711-Sum It Up 题解
- HDU-1711:Sum It Up
- Sum It Up poj 1711
- joj1197(深搜,Sum it up)
- poj 1564 Sum It Up | zoj 1711 | hdu 1548 (dfs + 剪枝 or 判重)
- ZOJ(1711)Sum It Up (DFS+剪枝+去重复)
- ZOJ 2729 Sum Up
- zju 1711——Sum It Up
- JDBC高级实例模板
- UITabBarController 继承和使用InterfaceBuilder
- typeid的作用
- JAVA中使用Socket实现自定义协议、无服务器即时通讯(类似飞秋)
- 网络运营之剑—html连接css
- zoj 1711 Sum It Up //深搜
- 公告:本博客继续使用!
- 把文件流中的图片按指定的大小保存到指定的文件中
- 用Visual C#调用Windows API函数
- excel表格操作
- Java各种数据类型详细介绍及其区别
- winpcap 安装
- Moziila文件结构概览
- sql存储过程分类