洛谷P3112 [USACO14DEC]后卫马克Guard Mark
Posted third2333
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了洛谷P3112 [USACO14DEC]后卫马克Guard Mark相关的知识,希望对你有一定的参考价值。
洛谷P3112 [USACO14DEC]后卫马克Guard Mark
1 #include <bits/stdc++.h> 2 #define For(i,j,k) for(int i=j;i<=k;i++) 3 #define LL long long 4 using namespace std ; 5 6 const int N = 21 ; 7 int n,H,res ; 8 LL sum ; 9 int dp[1100000],bin[21] ; 10 struct cow{ 11 int height,weight,pow ; 12 }a[N]; 13 14 inline int read() 15 { 16 int x = 0 , f = 1 ; 17 char ch = getchar() ; 18 while(ch<‘0‘||ch>‘9‘) { if(ch==‘-‘) f = -1 ; ch = getchar() ; } 19 while(ch>=‘0‘&&ch<=‘9‘) { x = x * 10+ch-48 ; ch = getchar() ; } 20 return x * f ; 21 } 22 23 int main() 24 { 25 n = read() ; H = read() ; 26 res = -1 ; 27 For(i,1,n) { 28 a[i].height = read() ; a[i].weight = read() ; a[i].pow = read() ; 29 } 30 memset(dp,-1,sizeof dp) ; 31 bin[0] = 1 ; 32 For(i,1,n) bin[i]=bin[i-1]*2 , dp[bin[i-1]] = a[i].pow ; 33 For(i,1,bin[n]-1) { 34 For(j,1,n) 35 if(!(i & bin[j-1])) 36 dp[i | bin[j-1] ] = max(dp[i | bin[j-1] ],min(dp[i]-a[j].weight,a[j].pow) ) ; 37 sum = 0 ; 38 For(j,1,n) 39 if(i & bin[j-1] ) sum=sum+ a[j].height ; 40 if(sum>=H) 41 if(res<dp[i]) 42 res = dp[ i ] ; 43 } 44 if(res>=0) printf("%d\n",res) ; 45 else printf("Mark is too tall") ; 46 return 0 ; 47 }
以上是关于洛谷P3112 [USACO14DEC]后卫马克Guard Mark的主要内容,如果未能解决你的问题,请参考以下文章
洛谷 P3111 [USACO14DEC]牛慢跑Cow Jog_Sliver
洛谷P3111 [USACO14DEC]牛慢跑Cow Jog_Sliver
洛谷 P3003 [USACO10DEC]苹果交货Apple Delivery
洛谷P3003 [USACO10DEC]苹果交货Apple Delivery