随笔分类 - DP——状态压缩
摘要:题目链接:http://lightoj.com/volume_showproblem.php?problem=1057题目大意:在二维矩阵中,给你一个起点和至多15个的目标点。要你求出从起点出发经过完所有的点后回到起点的最短路径值。每个点一步可以向 八个方向走。算法思路:一看就觉得是tsp,用状态压缩。而任意两点的距离就是相应横纵坐标差的较大值。具体看代码。代码:#include#include#include#includeusing namespace std;const int maxn = 1>T; for(int cas=1; cas>m>>n; char s
阅读全文
摘要:题目链接:http://lightoj.com/volume_showproblem.php?problem=1037#include#include#include#includeusing namespace std;const int maxn = 1>T; for(int cas=1; cas>N; for(int i=0; i0) add++; dp[S|1<<j] = min(dp[S|1<<j],dp[S] + add); } } } prin...
阅读全文
摘要:题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4284#include#include#include#includeusing namespace std;const int maxn = 105;const int maxm = 16;const int INF = 0x3f3f3f3f;int dp[maxm][1>T; while(T--){ cin>>N>>M>>Money; for(int i=0;i w) dist[u][v] = dist[v][u] = w; //...
阅读全文
摘要:题目链接:http://poj.org/problem?id=2288#include#include#include#includeusing namespace std;const int maxn = 13;typedef long long int ll_int;ll_int dp[maxn][maxn][1>T; while(T--){ int n,m; cin>>n>>m; memset(G,0,sizeof(G)); memset(dp,0,sizeof(dp)); memset(way,0,sizeof...
阅读全文
摘要:题目链接:http://lightoj.com/volume_showproblem.php?problem=1021#include#include#include#includeusing namespace std;const int maxn = 1>T; for(int cas=1;cas='0' && s[i] <= '9') num[i] = s[i] - '0'; else num[i] = 10 + s[i] - 'A'; } memset(dp,0,sizeof(dp)); ...
阅读全文
摘要:题目链接:http://poj.org/problem?id=3254#include #include #include #include #include #include #include using namespace std;const int moder = 1e8;const int maxe = 50000;const int maxn = 13;const int INF = 0x3f3f3f;int dp[maxn][1>M>>N; for(int i=1;i<=M;i++){ G[i] = 0; for(int j=0;j<N;j++)...
阅读全文
摘要:题目链接:http://lightoj.com/volume_showproblem.php?problem=1018#include #include #include #include #include #include #include using namespace std;const int maxe = 50000;const int maxn = 16;const int INF = 0x3f3f3f;int X[maxn],Y[maxn];int S[maxn][maxn];int T,N;int dp[1>T; for(int cas=1;cas<=T;cas++
阅读全文
摘要:#include #include #include #include #include #include #include using namespace std;const int maxe = 50000;const int maxn = 17;const int INF = 0x3f3f3f;int main(){ // freopen("E:\\acm\\input.txt","r",stdin); int N; int dp[1>N && N){ for(int i=0;i>m; P[i] = 1>x, P[
阅读全文