HDU1521 排列組合 生成函式 揹包

2022-04-29 20:51:08 字數 548 閱讀 1990

鏈結

可以用生成函式做,也可以用組合數做。

生成函式就是無腦算一下階乘暴力揹包,然後最後再乘上\(m\)的階乘

組合數的方法就是用類似揹包的轉移,轉移的時候考慮當前放的這幾個的方案數即可

#includeusing namespace std;

const int maxn = 23;

inline int read()

while(c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();

return x * f;

}int n, m = 22, v[maxn];

long long f[maxn][maxn], c[maxn][maxn], fac[maxn];

int main()

while(scanf("%d %d", &n, &m) != eof) }}

} cout << f[n][m] << '\n';

} return 0;

}

hdu 1521 排列組合

題意 problem description 有n種物品,並且知道每種物品的數量。要求從中選出m件物品的排列數。例如有兩種物品a,b,並且數量都是1,從中選2件物品,則排列有 ab ba 兩種。input 每組輸入資料有兩行,第一行是二個數n,m 1 m,n 10 表示物品數,第二行有n個數,分別表...

HDU 1521(排列組合)

母函式題,求排列使用指數型母函式,套用母函式模板即可。include include using namespace std const int maxn 15 int fac maxn 階乘 int num maxn double c1 maxn c2 maxn 計算10以內的階乘 void ge...

hdu1521 排列組合母函式)

problem description 有n種物品,並且知道每種物品的數量。要求從中選出m件物品的排列數。例如有兩種物品a,b,並且數量都是1,從中選2件物品,則排列有 ab ba 兩種。input 每組輸入資料有兩行,第一行是二個數n,m 1 m,n 10 表示物品數,第二行有n個數,分別表示這n...