03题的代码: #include <stdio.h> #include <vector> #include <algorithm> #include <string.h> #include <limits.h> #include <string> #include <iostream> #include <queue> #include <math.h> #include <map> #include <stack> #include <set> #include <list> #include <forward_list> #define left (now<<1) #define right ((now<<1)+1) #define mid ((l + r) >> 1) #define midmid ((r + mid) >> 1) #define LONG_LONG_MIN -9223372036854775808ll #define LONG_LONG_MAX 9223372036854775807ll using namespace std; typedef long long int ll; const int MAXN = 2e6 + 10; const int MOD = 1e9 + 7; ll dp[MAXN]; ll dl[30],cost[30]; int sum,n; ll dfs(int now){     if(dp[now] != -1){ return dp[now];}     if(now == sum){         return dp[now] = 0;     }     dp[now] = LONG_LONG_MAX / 2;     ll nowday = 0;     for(int i = 0; i <= n - 1; ++i){         int p = 1 << i;         if((p & now) == 0){             nowday = nowday + cost[i + 1];         }     }     for(int i = 0; i <= n - 1; ++i){         int p = 1 << i;         if((p & now) == 0){             int st = p | now;             ll need = max(0ll,nowday - dl[i + 1]);             dp[now] = min(dp[now],dfs(st) + need);         }     }     return dp[now]; } int main(){     while(scanf("%d",&n)!=EOF){         for(int i = 1; i <= n; ++i){             scanf("%lld%lld",&dl[i],&cost[i]);         }         memset(dp,-1,sizeof(dp)); sum = (1 << n) - 1;         dfs(0);         printf("%lld\n",dp[0]);     }     return 0; }
点赞 1

相关推荐

淬月星辉:专利是什么?至少描述一下吧,然后把什么计算机二级、普通话这种拉低格调的证书删掉,不然hr以为你没东西写
点赞 评论 收藏
分享
牛客网
牛客网在线编程
牛客网题解
牛客企业服务