判断能不能买到i单位的干草
1 #include<iostream> 2 #include<cstdio> 3 #include<cstdlib> 4 #include<algorithm> 5 #include<cstring> 6 #define re(i,l,r) for(int i=(l);i<=(r);i++) 7 #define rre(i,r,l) for(int i=(r);i>=(l);i--) 8 #define Clear(a,x) memset(a,x,sizeof(a)) 9 using namespace std; 10 void inin(int &x) 11 { 12 x=0;int f=0;char ch=getchar(); 13 while(ch<'0'||ch>'9'){if(ch=='-')f=1;ch=getchar();} 14 while(ch>='0'&&ch<='9')x*=10,x+=ch-'0',ch=getchar(); 15 x=f?-x:x; 16 } 17 int n,v[111],w[111],c; 18 int hh[55555]; 19 int main() 20 { 21 Clear(hh,127); 22 inin(n),inin(c); 23 re(i,1,n)inin(v[i]),inin(w[i]);hh[0]=0; 24 re(i,1,n)re(j,v[i],c+5000)hh[j]=min(hh[j],hh[j-v[i]]+w[i]); 25 int ans=2147483647; 26 re(i,c,c+5000)ans=min(ans,hh[i]); 27 cout<<ans; 28 return 0; 29 }