标签:style blog http color 使用 os
#include <stdio.h> #include <string.h> #include <map> #include <algorithm> using namespace std; #define INF 0x3f3f3f3f #define min(a,b) ((a)<(b)?(a):(b)) #define max(a,b) ((a)>(b)?(a):(b)) const int N = 25; const int M = (1<<20) + 5; int t, n, num[N], dp[M][8]; int dfs(int s, int k) { if (dp[s][k] != -1) return dp[s][k]; dp[s][k] = INF; if (s == (1<<n) - 1) return dp[s][k] = 0; int vis[8]; memset(vis, 0, sizeof(vis)); for (int i = 0; i < n; i++) { if (vis[num[i]]) continue; if (s&(1<<i)) continue; vis[num[i]] = 1; int t = dfs(s^(1<<i), max(0, num[i] - k - 1)) + max(1, num[i] - k); dp[s][k] = min(dp[s][k], t); } return dp[s][k]; } int main() { scanf("%d", &t); while (t--) { scanf("%d", &n); memset(dp, -1, sizeof(dp)); for (int i = 0; i < n; i++) scanf("%d", &num[i]); printf("%d\n", dfs(0, 0)); } return 0; }
UVA 11691 - Allergy Test(状压dp+贪心),码迷,mamicode.com
UVA 11691 - Allergy Test(状压dp+贪心)
标签:style blog http color 使用 os
原文地址:http://blog.csdn.net/accelerator_/article/details/24815687