dp,背包。 #include<cstdio> #include<cstring> #include<algorithm> using namespace std; int n,m,l; int dp[1005][105]; int main() { int t,i,j,k,len,val,ans; scanf("%d",&t); while (t--){ scanf("%d%d%d",&n,&m,&l); memset(dp,-1,sizeof(dp)); dp[0][0]=0; for (i=0;i<n;i++){ scanf("%d%d",&len,&val); for (j=l;j>=len;j--) for (k=m;k>=1;k--) if (dp[j-len][k-1]>=0&&dp[j-len][k-1]+val>dp[j][k]) dp[j][k]=dp[j-len][k-1]+val; } ans=0; for (i=0;i<=l;i++) ans=max(ans,dp[i][m]); printf("%d/n",ans); } return 0; }