讨论 / 滚动数组AC
song 2016-08-06 10:28:01
点我顶贴 收藏 删除
#include <stdio.h>

#define maxn 1005

int max(int,int);

int a[maxn] = {0},f[maxn] = {0};

int main()

{

int i,j;

int T,m;

int t,w;

scanf("%d %d",&T,&m);

for ( i=1; i<=m; i++){

scanf("%d %d",&t,&w);

for ( j=T; j>=t; j--) f[j] = max(f[j],f[j-t]+w);

}

printf("%d\n",f[T]);

return 0;

}

int max(int a,int b)

{

return a>b ? a:b;

}

查看更多回复
提交回复