Uva 10253 - Series-Parallel Networks 解题报告(递推)

96 篇文章 0 订阅

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



    解题报告:比较难搞的递推。主要是要能想到递推方程。不多说了,不懂就看书吧。(训练指南,p117)。

    代码如下:

#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);
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
CUDA Runtime API是一组用于访问和控制CUDA设备的函数和数据结构的库。CUDA是一种并行计算平台和编程模型,它可以提高计算密集型应用程序的性能。CUDA Runtime API提供了访问设备内存、执行并行计算、管理设备状态和连接多个GPU的功能。 版本1.5.2是CUDA Runtime API的一个特定版本,它包含了一些更新和改进。这些更新可能包括性能优化、新的功能特性和错误修复。用户可以根据他们的需求和硬件环境选择使用特定的版本。 当使用CUDA Runtime API进行并行计算时,可以使用多线程的方式同时处理大量数据。这种并行计算方式可以利用GPU在处理大规模数据集上的优势,加快计算速度。CUDA Runtime API提供了一系列的函数,如cudaMalloc()和cudaMemcpy(),用于在主机和设备之间分配和传输内存数据。它还提供了函数如cudaDeviceSynchronize(),用于同步设备上的并行计算任务。 CUDA Runtime API-1.5.2-parallel 的具体含义可能是指在这个版本中加强了并行计算能力。这可能包括了更好的线程管理、更高效的内存传输、更强大的GPU任务调度等方面的优化。这些改进可以帮助开发人员更好地利用CUDA设备并行计算的能力,提升应用程序的性能。 总之,CUDA Runtime API是一组用于访问和控制CUDA设备的函数和数据结构的库,版本1.5.2可能是指具有一些更新和改进的特定版本。通过使用CUDA Runtime API,开发人员可以利用GPU的并行计算能力,加快计算密集型应用程序的运行速度。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值