标签:mode desc ems ble 整数 输出 包含 完全背包 can
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 251 Accepted Submission(s): 125
1 #include<iostream> 2 #include<cstdio> 3 #include<cstdlib> 4 #include<cctype> 5 #include<cmath> 6 #include<cstring> 7 #include<map> 8 #include<set> 9 #include<queue> 10 #include<vector> 11 #include<algorithm> 12 #include<string> 13 #define ll long long 14 #define eps 1e-10 15 #define LL unsigned long long 16 using namespace std; 17 const int INF=0x3f3f3f3f; 18 const int N=100000+100; 19 const int mod=998244353; 20 int a[N],b[N]; 21 struct node{ 22 int k,p; 23 }val[N]; 24 ll dp[1010][20]; 25 ll minn[N]; 26 bool cmp(node a,node b) 27 { 28 return a.k-a.p<b.k-b.p; 29 } 30 int main() 31 { 32 int n,m; 33 while(scanf("%d%d",&n,&m)!=EOF) 34 { 35 int maxx1=0; 36 int maxx2=0; 37 memset(minn,INF,sizeof(minn)); 38 for(int i=0;i<n;i++){ 39 scanf("%d%d",&a[i],&b[i]); 40 maxx1=max(maxx1,b[i]); 41 } 42 for(int i=0;i<m;i++){ 43 scanf("%d%d",&val[i].k,&val[i].p); 44 maxx2=max(maxx2,val[i].p); 45 } 46 for(int i=0;i<1010;i++) 47 for(int j=0;j<20;j++)dp[i][j]=1e10; 48 for(int j=0;j<=10;j++)dp[0][j]=0; 49 sort(val,val+m,cmp); 50 for(int k=0;k<=10;k++) 51 for(int i=0;i<m;i++) 52 for(int j=1;j<=1000;j++){ 53 if(j-val[i].p+k<=0)dp[j][k]=min((ll)val[i].k,dp[j][k]); 54 else 55 dp[j][k]=min(dp[j][k],dp[j-val[i].p+k][k]+val[i].k); 56 57 } 58 ll ans=0; 59 for(int i=0;i<n;i++){ 60 ans=ans+dp[a[i]][b[i]]; 61 } 62 if(maxx2<=maxx1)cout<<-1<<endl; 63 else 64 printf("%I64d\n",ans); 65 } 66 return 0; 67 }
hdu 6082 度度熊与邪恶大魔王(2017"百度之星"程序设计大赛 - 资格赛 )
标签:mode desc ems ble 整数 输出 包含 完全背包 can
原文地址:http://www.cnblogs.com/Aa1039510121/p/7302382.html