标签:style blog http io color os ar for sp
那么现在问题就来了。。。
给你N(1=<N<=15)个任务,每个任务有一个截止完成时间t(1=<t<=10^8)和完成该任务需要的天数v(1=<v<=10^8),任务每超时一天惩罚加1,问最少能获得多少惩罚?
2 3 3 3 20 1 3 2 3 3 3 6 3 6 3
2 3
1 #include <iostream> 2 #include <cstdio> 3 #include <cstring> 4 #include <cmath> 5 #include <algorithm> 6 #include <climits> 7 #include <vector> 8 #include <queue> 9 #include <cstdlib> 10 #include <string> 11 #include <set> 12 #include <stack> 13 #define LL long long 14 #define pii pair<int,int> 15 #define INF 0x3f3f3f3f 16 using namespace std; 17 const int maxn = 16; 18 int n,dp[1<<maxn],cnt[1<<maxn],td[maxn],tm[maxn]; 19 int main() { 20 int T; 21 scanf("%d",&T); 22 while(T--){ 23 scanf("%d",&n); 24 int u = 1<<n; 25 for(int i = 0; i < n; ++i) 26 scanf("%d %d",td+i,tm+i); 27 memset(dp,0x3f,sizeof(dp)); 28 for(int i = 0; i < n; ++i) 29 dp[1<<i] = tm[i] > td[i]?tm[i] - td[i]:0; 30 for(int i = 1; i < u; ++i){ 31 cnt[i] = 0; 32 for(int k = 0; k < n; ++k) 33 if(i&(1<<k)) cnt[i] += tm[k]; 34 } 35 for(int i = 1; i < u; ++i){ 36 for(int k = 0; k < n; ++k){ 37 if(i&(1<<k)) continue; 38 int tmp = cnt[i] + tm[k] - td[k]; 39 if(tmp > 0) dp[i^(1<<k)] = min(dp[i^(1<<k)],dp[i] + tmp); 40 else dp[i^(1<<k)] = min(dp[i^(1<<k)],dp[i]); 41 } 42 } 43 printf("%d\n",dp[u-1]); 44 } 45 return 0; 46 }
标签:style blog http io color os ar for sp
原文地址:http://www.cnblogs.com/crackpotisback/p/4063502.html