POJ 2248 搜索】的更多相关文章

剪枝: 1.从后向前枚举 2.迭代加深 然后就0msAC了 //By SiriusRen #include <cstdio> using namespace std; int n,T,s[105]; bool dfs(int t){ if(s[t]==n)return 1; if(t>=T)return 0; for(int i=t;i>=1;i--){ s[t+1]=s[i]+s[t]; if(dfs(t+1))return 1; } } int main(){ s[1]=1;…
catch that cow POJ 3278 搜索 题意 原题链接 john想要抓到那只牛,John和牛的位置在数轴上表示为n和k,john有三种移动方式:1. 向前移动一个单位,2. 向后移动一个单位,3. 移动到当前位置的二倍处.输出移动的最少次数. 解题思路 使用搜索,准确地说是广搜,要记得到达的位置要进行标记,还有就是减枝. 详情见代码实现. 代码实现 #include<cstdio> #include<cstring> #include<iostream>…
[题目描述] An addition chain for n is an integer sequence with the following four properties: a0 = 1 am = n a0 < a1 < a2 < ... < am-1 < am For each k (1<=k<=m) there exist two (not necessarily different) integers i and j (0<=i, j<=k…
[题目链接] http://poj.org/problem?id=2248 [算法] 搜索剪枝 剪枝1 : 优化搜索顺序,从大到小枚举 剪枝2 : Ai + Aj可能相等,只需搜一次即可 剪枝3 : 通过观察发现 : m <= 10,可以用迭代加深搜索 [代码] #include <algorithm> #include <bitset> #include <cctype> #include <cerrno> #include <clocale&…
题目链接:http://bailian.openjudge.cn/practice/2248 题解: 迭代加深DFS. DFS思路:从目前 $x[1 \sim p]$ 中选取两个,作为一个新的值尝试放入 $x[p+1]$. 迭代加深思路:设定一个深度限制,一旦到达这个界限,即继续往下搜索:该深度限制从 $1$ 开始,每次自加 $1$.这么做的好处是,正好也符合题目要求的最短的数组长度. AC代码: #include<bits/stdc++.h> using namespace std; ];…
目录 POJ 1426 POJ 1321 POJ 2718 POJ 3414 POJ 1416 POJ 2362 POJ 3126 POJ 3009 个人整了一些搜索的简单题目,大家可以clone来练习,vjudge链接直接公开了.以下部分代码省略了头文件,总之each就是for循环,rush()就是输入T个样例然后while(T--) vjudge练习地址:https://vjudge.net/contest/330414 POJ 1426 二进制的数实在太大了,所以用数组下标直接代表二进制数…
Dungeon Master Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 13923   Accepted: 5424 Description You are trapped in a 3D dungeon and need to find the quickest way out! The dungeon is composed of unit cubes which may or may not be filled…
题目链接:http://poj.org/problem?id=1011 #include<cstdio> #include<cstring> #include<algorithm> #include<iostream> using namespace std; ; int a[maxn]; int N; int sum; int len,cnt; bool used[maxn]; bool cmp(int a,int b){ return a > b;…
Description An addition chain for n is an integer sequence with the following four properties: a0 = 1 am = n a0 < a1 < a2 < ... < am-1 < am For each k (1<=k<=m) there exist two (not necessarily different) integers i and j (0<=i, j&…
An addition chain for n is an integer sequence <a0, a1,a2,...,am=""> with the following four properties: a0 = 1 am = n a0 < a1 < a2 < ... < am-1 < am For each k (1<=k<=m) there exist two (not necessarily different) int…