D e s c r i p t i o n Description Description
DP
01背包
I n p u t Input Input
第一行,时间T
第二行,作业的数量n
第3~n+2行,所需时间Time和批评的愤怒值Num
O u t p u t Output Output
一行,必须接受的愤怒值和
S a m p l e Sample Sample I n p u t Input Input
5
3
2 6
1 3
4 7
S a m p l e Sample Sample O u t p u t Output Output
6
思路
DP
01背包
#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdio>
using namespace std;
int Time,Num,Sum,n,m;
int F[100005];
int main()
{
freopen("homework.in","r",stdin);
freopen("homework.out","w",stdout);
scanf("%d%d",&m,&n);
for(int i=1;i<=n;++i)
{
scanf("%d%d",&Time,&Num);
Sum+=Num;
for(int j=m;j>=1;--j)
if(j-Time>=0)
{
F[j]=max(F[j],F[j-1]);
F[j]=max(F[j],F[j-Time]+Num);
}
}
printf("%d",Sum-F[m]);
fclose(stdin);
fclose(stdout);
return 0;
}