http://acm.hdu.edu.cn/showproblem.php?pid=2159
#include<iostream>
#include<iomanip>
using namespace std;
int n, m, k, s, a, b;
int dp[110], S[110], A[110], B[110], count[110];
int main()
{
int i, j;
while( scanf( "%d%d%d%d",&n, &m, &k, &s ) != EOF )
{
for( i = 1; i <= k; i++ )
{
scanf( "%d%d",&A[i], &B[i] );
}
memset( dp,0,sizeof(dp) );
memset( count,0,sizeof(count) );
int flag = -1;
for( i = 1; i <= k; i++ )
{
for( j = B[i]; j <= m; j++ )
{
if( dp[j] < dp[j-B[i]]+A[i] )
{
dp[j] = dp[j-B[i]]+A[i];
count[j] = count[j-1]+1;//关键不能搞错
}
}
}
for(i=0;i<=m;i++)
{
if(dp[i]>=n&&count[i]<=s)break;
}
cout<<m-i<<endl;
}
return 0;
}