hdu 3496 Watch The Movie

#include <stdio.h>
#include <string.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <math.h>
#include <stdlib.h>
#include <time.h>
using namespace std;

const int inf=1<<24;
int main()
{
    int _,i,j,k,n,m,l,dp[100+5][1000+24],a[100+5],b[100+5];
    scanf("%d",&_);
    while(_--)
    {
        scanf("%d%d%d",&n,&m,&l);
        for(i=0; i<n; i++)
        {
            scanf("%d%d",&a[i],&b[i]);
        }
        for(i=0;i<=100;i++)
            for(j=0;j<1024;j++)
        {
            if(i==0) dp[i][j]=0;
            else dp[i][j]=-inf;
        }

        for(k=0; k<n; k++)
        {
            for(i=m; i>=1; i--)
            {
                for(j=l; j>=a[k]; j--)
                    {
                        dp[i][j]=max(dp[i][j],dp[i-1][j-a[k]]+b[k]);
                    }
            }
        }

        if(dp[m][l]<0) printf("0
");
        else printf("%d
",dp[m][l]);
    }
    return 0;
}
原文地址:https://www.cnblogs.com/blfbuaa/p/7363351.html