//蓝桥杯-算法训练 开心的金明 //评测结果 AC //动态规划 01背包 #include <cstdio> #include <algorithm> #include <cstring> using namespace std; const int maxn = 30005; int main() { int N, m; scanf( "%d%d", &N, &m ); int f[maxn]; int v, w; memset( f, 0, sizeof( f ) ); for( int i = 1; i <= m; i++ ) { scanf( "%d%d", &v, &w ); for( int j = N; j >= 0; j-- ) if( j >= v ) f[j] = max( f[j], f[j - v] + w * v ); } printf( "%d", f[N] ); return 0; }
时间: 2024-12-21 04:41:06