POJ 2248】的更多相关文章

[题目链接] 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; ];…
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…
#include <iostream> #define MAXN 100 #define min __min using namespace std; int tem[MAXN]; int _min[MAXN]; int n; int min; void DFS(int num,int index); int main() { //freopen("acm.acm","r",stdin); int i; int k; int index; while(c…
枚举ak的值 反向枚举使ak尽快到达最短链的n /*H E A D*/ int n,m,a[23333],dep; bool dfs(int x){ if(a[x-1]>n||a[x-1]<=a[x-2])return 0; if(x>dep){ if(a[x-1]==n) return 1; else return 0; } // rep(i,1,x-1){ // rep(j,1,x-1){ rrep(i,x-1,1){ rrep(j,x-1,i){ a[x]=a[i]+a[j]; i…
原题 给出数n,求出1......n 一串数,其中每个数字分解的两个加数都在这个序列中(除了1,两个加数可以相同),要求这个序列最短. ++m,dfs得到即可.并且事实上不需要提前打好表,直接输出就可以. #include<cstdio> using namespace std; int dep=0,n; int a[102]; bool dfs(int step) { if(step>dep) return a[dep]==n; for(int i=0;i<step;i++) {…
剪枝: 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;…
[题目描述] 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…
poj 题目分类 按照ac的代码长度分类(主要参考最短代码和自己写的代码) 短代码:0.01K--0.50K:中短代码:0.51K--1.00K:中等代码量:1.01K--2.00K:长代码:2.01K以上. 短:1147.1163.1922.2211.2215.2229.2232.2234.2242.2245.2262.2301.2309.2313.2334.2346.2348.2350.2352.2381.2405.2406: 中短:1014.1281.1618.1928.1961.2054…