UVA 10253 - Series-Parallel Networks(数论+计数问题+递推)
题目链接:10253 - Series-Parallel Networks
#include <stdio.h> #include <string.h> #include <stdlib.h> #include <algorithm> using namespace std; long long C(long long n, long long m) { double ans = 1; for (int i = 0; i < m; i++) { ans *= n - i; } for (int i = 0; i < m; i++) ans /= i + 1; return (long long)(ans + 0.5); } const int N = 31; int n; long long f[N]; long long dp[N][N]; int main() { f[1] = 1; for (int i = 0; i < N; i++) dp[i][0] = 1; for (int i = 1; i < N; i++) {dp[i][1] = 1; dp[0][i] = 0;} for (int i = 1; i < N; i++) { for (int j = 2; j < N; j++) { dp[i][j] = 0; for (int p = 0; p * i <= j; p++) { dp[i][j] += C(f[i] + p - 1, p) * dp[i - 1][j - p * i]; } } f[i + 1] = dp[i][i + 1]; } while (~scanf("%d", &n) && n) { printf("%lld\n", n == 1 ? 1 : 2 * f[n]); } system("pause"); return 0; }
UVA 10253 - Series-Parallel Networks(数论+计数问题+递推),古老的榕树,5-wow.com
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。