标签:保留 接下来 col for lin rip break 一个 ott
#include <cstdio> #include <map> #include <iostream> #include<cstring> #include<bits/stdc++.h> #define ll long long int #define M 6 using namespace std; inline ll gcd(ll a,ll b){return b?gcd(b,a%b):a;} inline ll lcm(ll a,ll b){return a/gcd(a,b)*b;} int moth[13]={0,31,28,31,30,31,30,31,31,30,31,30,31}; int dir[4][2]={1,0 ,0,1 ,-1,0 ,0,-1}; int dirs[8][2]={1,0 ,0,1 ,-1,0 ,0,-1, -1,-1 ,-1,1 ,1,-1 ,1,1}; const int inf=0x3f3f3f3f; const ll mod=1e9+7; int n,m,k,s; //经验值,忍耐度,怪物类型,最大杀怪数 int a[107]; //得到的经验值 int b[107]; //消耗的忍耐度 int dp[107][107]; //i忍耐度下杀j只怪得到的最高经验 int main(){ ios::sync_with_stdio(false); while(cin>>n>>m>>k>>s){ memset(dp,0,sizeof(dp)); for(int i=1;i<=k;i++) cin>>a[i]>>b[i]; for(int i=1;i<=k;i++) for(int j=1;j<=s;j++){ for(int kk=b[i];kk<=m;kk++){ dp[kk][j]=max(dp[kk][j],dp[kk-b[i]][j-1]+a[i]); } } int ans=-1; for(int i=1;i<=m;i++){ for(int j=1;j<=s;j++){ if(dp[i][j]>=n){ ans=i; break; } } if(ans==i) break; } if(ans==-1) cout<<ans<<endl; else cout<<m-ans<<endl; } }
标签:保留 接下来 col for lin rip break 一个 ott
原文地址:https://www.cnblogs.com/wmj6/p/10371518.html