某岛

… : "…アッカリ~ン . .. . " .. .
August 4, 2010

状态压缩DP

还有几道题正在整理。。还有几道题不会做。。
这几份题目都是类TSP问题。某一个参数小。可以用状态压缩DP可以解~~~

#include 
#include 
#include 
using namespace std;
const int N = 10, M = 1 << 10;
int w[N][N]; int dp[M][N];
string s[N];
int n, m, ans;


// updata the w[a][b] with the offset o;
int f(int a, int b, int o){
    int res = 0, o1, o2;
    if (o<0) o1 = -o, o2 = 0; else o1 = 0, o2 = o;

    for (int i=o1,j=o2;i> s[i];

    memset(w, 0, sizeof(w));
    for (int i=0;i> n;
    while (n!=0){
        init(); solve();
        cout << ans << endl;
        cin >> n;
    }
}
#include 
using namespace std;
const int N = 15, M = (1 << 15) - 1;
const int INF = 10000000;
int dp[M][N], w[N][N];
int n, m, k;
int ans;

void init(){
    int i, j;
    m = (1 << n); k--;
    int a[N], b[N];

    for (i=0;i> a[i] >> b[i];

    for (i=0;i> w[i][j];
            if (i==j) w[i][j] = -INF;
            else  w[i][j] = b[j] - a[j] - w[i][j];
        }

    for (i=0;i> n >> k){
        init();  solve(); // patch();
        cout << ans << endl;
    }
}