C数列 vijos P1350 IDS 搜索
来源:互联网 发布:淘宝买电棍犯法吗 编辑:程序博客网 时间:2024/06/07 21:47
见前一发题解,无非就是把数字的范围换了一下,运算的方式换了一下
并没有什么
传送门
下面是代码
#include <stdio.h>#include <string.h>#include <iostream>#include <algorithm>#define N 1000using namespace std;int a[N];int ar=1;bool s=false;int x;bool DFS(int depth,int sum,int will){ /*printf("check at LINE 13\n"); printf("depth=%d sum=%d will=%d\n",depth,sum,will); for(int i=1;i<=ar;++i) cout<<a[i]<<" "; puts("");*/ if(depth>will){if(sum==x){return true;}return false;} /*printf("%d depth=%d will=%d a[%d]=%d\n",sum<<(will-depth-1) ,depth,will,ar,a[ar]);*/ if(sum<<(will-depth+1)<x)return false; for(int i=ar;i>=1;--i) if(sum+a[i]<=x) {a[++ar]=sum+a[i];if(DFS(depth+1,sum+a[i],will))return true;ar--;} return false;}int main(){ cin>>x; a[1]=1; int cnt=0; while(1) { ++cnt; if(DFS(1,1,cnt))break; } cout<<cnt+1<<endl; for(int i=1;i<=ar;++i) cout<<a[i]<<" ";}
0 0
- C数列 vijos P1350 IDS 搜索
- 埃及分数 IDS 搜索 Vijos 1308
- 【IDDFS】【vijos 1350】C数列
- Vijos P1974 金币【数列】
- Vijos P1127 级数求和【数列】
- vijos 1321 搜索
- vijos P1099虫食算【搜索
- 埃及分数 迭代加深搜索 IDS
- vijos - P1319数列 (二进制 + 找规律 + python)
- 迭代加深搜索 + dp vijos 1159
- vijos-p1599 货币 -记忆化搜索
- [记忆化搜索]vijos 1599 货币
- C#、ASP.NET主键到底怎么写比较好?ID?Id?id?IDs?Ids?ids?欢迎大家指点
- C#、ASP.NET主键到底怎么写比较好?ID?Id?id?IDs?Ids?ids?欢迎大家指点
- vijos - P1176奇怪的数列 (递归 + 找规律)
- Codeforces Round #299 (Div. 2) C. Tavas and Karafs 二分搜索+数列
- PAT--完美数列-快速搜索
- (sscanf,sprintf)Cabric Number Problem(P1350)
- C# DateTime.Now.ToString("yyyy-MM-dd");
- Java_io体系之CharArrayReader、CharArrayWriter简介
- hash算法(hashmap实现原理)
- socket的概念与网络通信要素
- ThreadPoolExecutor使用和思考(上)-线程池大小设置与BlockingQueue的三种实现区别
- C数列 vijos P1350 IDS 搜索
- 启动摄像头,采集图片
- Layout _width ,Layout_height和heigh ,width 区别:
- ThreadPoolExecutor使用和思考(中)-keepAliveTime及拒绝策略
- Tomcat配置虚拟路径,使上传文件与服务器分离
- jquery插件——书写规范
- 敏捷UX开发与UCD
- RadioGroup,Android的单选框。
- 我们要相信我们自己