注意除个1000就不会超时了.....好吧.....不A了....去见女神了!哈哈哈哈哈哈哈哈哈哈哈哈哈!!!!
差点忘记贴代码了....
AC代码如下:
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
int dp[50000];
inline int max( int a, int b ){
return ( a > b ? a : b );
}
int main(){
int T;
int money, month, N;
int w[11], v[11];
int temp;
scanf( "%d", &T );
while( T-- ){
cin >> money >> month;
cin >> N;
for( int i = 0; i < N; i++ ){
scanf( "%d%d", &w[i], &v[i] );
w[i] /= 1000;
}
for( int k = 0; k < month; k++ ){
memset( dp, 0, sizeof( dp ) );
temp = money / 1000;
for( int i = 0; i < N; i++ ){
for( int j = w[i]; j <= temp; j++ ){
dp[j] = max( dp[j], dp[j-w[i]] + v[i] );
}
}
money += dp[temp];
}
cout << money << endl;
}
return 0;
}