You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.
# include <bits/stdc++.h>
using namespace std ;
const int N = 1010 , M = 10010 ;
int T , n , m ;
int f [ M ] ;
int w [ N ] [ N ] ; //第i天,第j支股票的价格
int main ( ) {
//未来天数 T, 纪念品数量 N, 小伟现在拥有的金币数量 M
cin > > T > > n > > m ;
for ( int i = 1 ; i < = T ; i + + ) //未来T天
for ( int j = 1 ; j < = n ; j + + ) //每个纪念品
cin > > w [ i ] [ j ] ; //价格
//优化版本
for ( int t = 1 ; t < T ; t + + ) { //枚举每一天
memset ( f , 0 , sizeof f ) ; // dp数组
for ( int i = 1 ; i < = n ; i + + ) //枚举前i种物品
if ( w [ t + 1 ] [ i ] > w [ t ] [ i ] ) //可以加的优化:只有在价值为正数时才会考虑使用该物品
for ( int j = w [ t ] [ i ] ; j < = m ; j + + ) //枚举剩余体积
f [ j ] = max ( f [ j ] , f [ j - w [ t ] [ i ] ] + w [ t + 1 ] [ i ] - w [ t ] [ i ] ) ;
//收益累加
m + = f [ m ] ;
}
printf ( " %d \n " , m ) ;
return 0 ;
}