随笔分类 - 搜索——dfs+记忆化+减枝
摘要:题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4433题目大意:给你一连串密码,(密码是0-》9循环转动),求最少的步骤到达目标数码。算法思路:这个题一看就觉得要用dp思想,就是方程不好想,抓住题目给的可以连续拨动1-3密码,我的dp[i][j][k]表示第i个数字为j,第i+1个数字为k,i及以后到达目标所有的最少步骤。然后记忆化搜。代码:#include#include#include#includeusing namespace std;int dp[1050][10][10];char in[1050],out[1050];int len
阅读全文
摘要:#include#include#include#includeusing namespace std;const int INF = 32000;const int maxn = 105;int a[maxn];char ans[maxn]; //a[i] = 1代表+,2代表-,3代表*,4代表/ ;int len,goal;bool vis[maxn][INF+1][2]; // vis[i][j][1]=1 表示计算完前i个数字的某种组合可以得到正j,dp[i][j][0]=1则为负jbool dfs(int u,int sum){ if(u == 1){ i...
阅读全文
摘要:题目链接:http://poj.org/problem?id=1011#include#include#include#includeusing namespace std;const int maxn = 100;int a[maxn];int N;int sum;int len,cnt;bool used[maxn];bool cmp(int a,int b){ return a > b;}bool dfs(int u,int curlen,int num){ if(num == cnt) return true; for(int i=u;i>N && N){
阅读全文
摘要:好苦逼,为啥数组开小了,不会runtime error,还得我WA了几个小时,我泪流满面。题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4620#include#include#include#include#includeusing namespace std;const int maxn = 35;struct Cut{ int T; int icnt; int bef_id; int a[11]; bool operator anspv){ anspv = deep; copy(t...
阅读全文
摘要:题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4499//主要剪枝:避免与以前枚举的发生冲突。要回溯即把G[x][y]归零。#include #include #include #include #include #include #include using namespace std;const int maxe = 50000;const int maxn = 10;const int INF = 0x3f3f3f;int N,M,Q;int G[maxn][maxn];int ans;void dfs(int x,int y,int v.
阅读全文
摘要:题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4705#pragma comment(linker, "/STACK:16777216")#include #include #include #include #include #include #include using namespace std;const int maxn = 110010;long long dp[maxn];vector G[maxn];long long num[maxn];long long N;long long ans;void dfs(i
阅读全文