Uva 10253 - Series-Parallel Networks 解题报告(递推)
来源:互联网 发布:flyme5 root软件 编辑:程序博客网 时间:2024/06/05 06:07
Problem H
Series-Parallel Networks
Input: standard input
Output: standard output
Time Limit: 5 seconds
Memory Limit: 32 MB
In this problem you are expected to count two-terminal series-parallel networks. These are electric networks considered topologically or geometrically, that is, without the electrical properties of the elements connected. One of the two terminals can be considered as the source and the other as the sink.
A two-terminal network will be considered series-parallel if it can be obtained iteratively in the following way:
q A single edge is two-terminal series-parallel.
q If G1 and G2 are two-terminal series-parallel, so is the network obtained by identifying the sources and sinks, respectively (parallel composition).
q If G1 and G2 are two-terminal series-parallel, so is the network obtained by identifying the sink ofG1 with the source of G2 (series composition).
Note here that in a series-parallel network two nodes can be connected by multiple edges. Moreover, networks are regarded as equivalent, not only topologically, but also when interchange of elements in series brings them into congruence; otherwise stated, series interchange is an equivalence operation. For example, the following three networks are equivalent:
Similarly, parallel interchange is also an equivalence operation. For example, the following three networks are also equivalent:
Now, given a number N, you are expected to count the number of two-terminal series parallel networks containing exactly N edges. For example, for N = 4, there are exactly 10 series-parallel networks as shown below:
Input
Each line of the input file contains an integer N (1 £ N £ 30) specifying the number of edges in the network.
A line containing a zero for N terminates the input and this input need not be considered.
Output
For each N in the input file print a line containing the number of two-terminal series-parallel networks that can be obtained using exactly N edges.
Sample Input
1
4
15
0
Sample Output
1
10
1399068
代码如下:
#include <cstdio>#include <cstring>#include <algorithm>#include <cmath>using namespace std;typedef long long LL;LL dp[100][100];LL C(LL x,int y){ double tmp=0; for(int i=1;i<=y;i++) tmp+=log10(x-i+1)-log10(i); return (LL)(pow(10,tmp)+0.5);}LL dfs(int x,int y){ if(y==0) return 0; if(x==1||y==1||x==0) return 1; LL &ans=dp[x][y]; if(~ans) return ans; ans=0; for(int i=0;i*y<=x;i++) ans+=dfs(x-i*y,y-1)*C(dfs(y,y-1)+i-1,i); return ans;}int main(){ memset(dp,-1,sizeof(dp)); int n; while(~scanf("%d",&n) && n) printf("%lld\n", n==1?1:dfs(n,n-1)*2);}
- Uva 10253 - Series-Parallel Networks 解题报告(递推)
- UVA 10253 - Series-Parallel Networks(数论+计数问题+递推)
- Series-Parallel Networks UVA 10253
- uva 10253 - Series-Parallel Networks
- UVa 10253 Series-Parallel Networks
- UVA 10253Series-Parallel Networks
- uvaoj 10253 - Series-Parallel Networks
- uva10253 Series-Parallel Networks
- uva 10253 Series-Parallel Networks 树的性质,可重排列
- Uva 11375 Matches 解题报告(递推+高精度)
- Uva 11137 Ingenuous Cubrency 解题报告(递推)
- Uva 1393 - Highways 解题报告(递推)
- Uva 11645 - Bits 解题报告(递推+大数)
- Uva 10079 - Pizza Cutting 解题报告(递推)
- Uva 10081 - Tight Words 解题报告(递推)
- Uva 10157 - Expressions 解题报告(递推)
- Uva 580 - Critical Mass 解题报告(递推)
- UVa-10891 Game of Sum ACM解题报告(递推O(n^2)算法)
- 我们到底在定制什么
- eclipse启动tomcat无法访问报404
- 关于设计表时应该注意的问题
- UFT\QTP 12 新特性
- NAT再解析(详)
- Uva 10253 - Series-Parallel Networks 解题报告(递推)
- VA 快捷键(很好的文章)
- [JavaScript] Use template engine in Dojo
- C语言中return的含义
- MMS解析
- LeetCode:Simplify Path
- 如果你失去了我,你會不會傷心流淚
- 高级语法-虚拟语气
- linux(Centos 7) 安装php和nginx