HDU-1028 Ignatius and the Princess III(生成函数)
生活随笔
收集整理的這篇文章主要介紹了
HDU-1028 Ignatius and the Princess III(生成函数)
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
題意
給出$n$,問用$1$到$n$的數字問能構成$n$的方案數
思路
生成函數基礎題,$x^{n}$的系數即答案。
代碼
#include <bits/stdc++.h> #define DBG(x) cerr << #x << " = " << x << endl;using namespace std;const int N = 120 + 5;int n, c[2][N];int main() {while(~scanf("%d", &n)) {for(int i = 0; i <= n; i++) c[1][i] = 1, c[0][i] = 0;for(int i = 2; i <= n; i++) {for(int j = 0; j <= n; j++) {for(int k = 0; k + j <= n; k += i) c[i & 1][k + j] += c[1 - (i & 1)][j];}for(int j = 0; j <= n; j++) c[1 - (i & 1)][j] = 0;}printf("%d\n", c[n & 1][n]);}return 0; }
轉載于:https://www.cnblogs.com/DuskOB/p/10604288.html
總結
以上是生活随笔為你收集整理的HDU-1028 Ignatius and the Princess III(生成函数)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 【笔试题】京东2017秋招笔试真题
- 下一篇: 从排序数组中删除重复项