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 = 110 ;
int n , m ;
int f [ N ] [ N ] ; //第一维: 前i个物品, 第二维: 体积j及以下
int main ( ) {
//文件输入
freopen ( " ZhiDuo_01.in " , " r " , stdin ) ;
scanf ( " %d %d " , & n , & m ) ;
//初始化
//在前0个物品中选, 所有合法空间, 都有一种结果, 就是啥也不要, 啥也不要也满足“不超过j”这个条件, 方案数=1。
for ( int i = 0 ; i < = m ; i + + ) f [ 0 ] [ i ] = 1 ;
for ( int i = 1 ; i < = n ; i + + ) {
int v ;
scanf ( " %d " , & v ) ;
/*写法1*/
for ( int j = 0 ; j < = m ; j + + ) {
if ( j > = v )
f [ i ] [ j ] = f [ i - 1 ] [ j ] + f [ i - 1 ] [ j - v ] ;
else
f [ i ] [ j ] = f [ i - 1 ] [ j ] ;
}
/*写法2*/
// for (int j = 0; j <= m; j++) {
// f[i][j] = f[i - 1][j]; //不被i件物品
// if (j >= v) f[i][j] += f[i - 1][j - v]; //能装下就要加上可以转移过来状态的方案数
// }
}
printf ( " %d \n " , f [ n ] [ m ] ) ;
return 0 ;
}