UVa Online Judge

  题意是计算给定数量的边通过串联并联两种方式,能组成多少种不同的网络。将它转化为一个树形结构,也就是求有多少不同构的树。

代码如下:

 #include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring> using namespace std; typedef long long LL;
const int N = ;
LL ans[N];
int s[N], top; LL com(LL n, LL m) {
LL ret = ;
for (int i = ; i < m; i++) ret *= n - i, ret /= i + ;
return ret;
} void dfs(int r, int x) {
if (r <= ) {
if (top <= ) return ;
int cnt = ;
LL tmp = ;
for (int i = ; i <= top; i++) {
if (s[i] == s[i + ]) cnt++;
else {
tmp *= com(ans[s[i]] + cnt - , cnt);
cnt = ;
}
}
ans[x] += tmp;
return ;
}
for (int i = s[top]; i <= r; i++) {
s[++top] = i, s[top + ] = -;
dfs(r - i, x);
top--;
}
} void PRE() {
ans[] = ;
for (int i = ; i < N; i++) {
s[top = ] = ;
ans[i] = ;
dfs(i, i);
//cout << i << ' ' << ans[i] << endl;
}
for (int i = ; i < N; i++) ans[i] <<= ;
} int main() {
PRE();
int n;
while (cin >> n && n) cout << ans[n] << endl;
return ;
}

UPD:

 #include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring> using namespace std; typedef long long LL;
const int N = ;
LL dp[N][N], ans[N]; LL com(LL n, LL m) {
LL ret = ;
for (int i = ; i < m; i++) {
ret *= n - i;
ret /= i + ;
}
return ret;
} void PRE() {
ans[] = ;
dp[][] = ;
for (int i = ; i < N; i++) {
dp[i][] = dp[i][] = ;
for (int j = ; j < N; j++) {
dp[i][j] = ;
for (int k = ; k * i <= j; k++) {
dp[i][j] += com(ans[i] + k - , k) * dp[i - ][j - k * i];
}
}
ans[i + ] = dp[i][i + ];
//cout << ans[i + 1] << endl;
}
} int main() {
PRE();
int n;
while (cin >> n && n) cout << (n > ? ans[n] << : ) << endl;
return ;
}

——written by Lyon

uva 10253 Series-Parallel Networks (整数划分+多重集)的更多相关文章

  1. UVA 10253 Series-Parallel Networks (树形dp)

    转载请注明出处: http://www.cnblogs.com/fraud/          ——by fraud Series-Parallel Networks Input: standard ...

  2. 蓝书例题之UVa 10253 Series-Parallel Networks

    挺有趣的一道题 首先转化模型,思路参考蓝书,可得出等同于求共n个叶子,且每个非叶结点至少有两个子结点的无标号树的个数的二倍,设个数为\(f[n]\) 考虑怎么求\(f[n]\),假设有一个\(n\)的 ...

  3. 51nod p1201 整数划分

    1201 整数划分 基准时间限制:1 秒 空间限制:131072 KB 分值: 80 难度:5级算法题 将N分为若干个不同整数的和,有多少种不同的划分方式,例如:n = 6,{6} {1,5} {2, ...

  4. 2014北大研究生推免机试(校内)-复杂的整数划分(DP进阶)

    这是一道典型的整数划分题目,适合正在研究动态规划的同学练练手,但是和上一个随笔一样,我是在Coursera中评测通过的,没有找到适合的OJ有这一道题(找到的ACMer拜托告诉一声~),这道题考察得较全 ...

  5. 整数划分 (区间DP)

    整数划分(四) 时间限制:1000 ms  |  内存限制:65535 KB 难度:3   描述 暑假来了,hrdv 又要留学校在参加ACM集训了,集训的生活非常Happy(ps:你懂得),可是他最近 ...

  6. nyoj 90 整数划分

    点击打开链接 整数划分 时间限制:3000 ms  |  内存限制:65535 KB 难度:3 描述 将正整数n表示成一系列正整数之和:n=n1+n2+-+nk,  其中n1≥n2≥-≥nk≥1,k≥ ...

  7. 整数划分 Integer Partition(二)

    本文是整数划分的第二节,主要介绍整数划分的一些性质. 一 先来弥补一下上一篇文章的遗留问题:要求我们所取的 (n=m1+m2+...+mi )中  m1 m2 ... mi连续,比如5=1+4就不符合 ...

  8. 整数划分 Integer Partition(一)

    话说今天百度面试,可能是由于我表现的不太好,面试官显得有点不耐烦,说话的语气也很具有嘲讽的意思,搞得我有点不爽.Whatever,面试中有问到整数划分问题,回答这个问题过程中被面试官搞的不胜其烦,最后 ...

  9. 51nod1201 整数划分

    01背包显然超时.然后就是一道神dp了.dp[i][j]表示j个数组成i的方案数.O(nsqrt(n)) #include<cstdio> #include<cstring> ...

随机推荐

  1. java开发岗位面试整理

    一.Java基础 1. String类为什么是final的 2. HashMap的源码,实现原理,底层结构. 3. 说说你知道的几个Java集合类:list.set.queue.map实现类. 4. ...

  2. java 字符串拼接

    package com.fh.controller.pacm.checkbill; import com.google.common.base.Joiner; /** * 字符串拼接 * * @aut ...

  3. ZOJ3195 Design the city [2017年6月计划 树上问题04]

    Design the city Time Limit: 1 Second      Memory Limit: 32768 KB Cerror is the mayor of city HangZho ...

  4. Codeforces 300C

    题目链接: http://codeforces.com/contest/300/problem/C 本来是道不难的题目,还是自己的数学功底不扎实. 从该题又一次巩固了关于乘法逆的概念,在剩余系中,如果 ...

  5. 【JZOJ5071】【GDSOI2017第二轮模拟】奶酪 树形dp

    题面 CJY很喜欢吃奶酪,于是YJC弄到了一些奶酪,现在YJC决定和CJY分享奶酪. YJC弄到了n-1块奶酪,于是他把奶酪挂在了一棵n个结点的树上,每根树枝上挂一块奶酪,每块奶酪都有重量. YJC和 ...

  6. css清除浮动各方法与原理

    说到清除浮动的方法,我想网络上应该有不下7,8的方法,介绍这些方法之前,想下为什么清除浮动? 再次回到float这个属性,浮动元素(floats)会被移出文档流,不会影响到块状盒子的布局而只会影响内联 ...

  7. at: 安排一个任务在未来执行,需要一个atd的系统后台进程

    检查atd进程是否启动 [root@centos61 桌面]# service atd status atd (pid  2274) 正在运行... [root@centos61 桌面]# chkco ...

  8. 如何用KNIME进行情感分析

    Customer Intelligence Social Media Finance Credit Scoring Manufacturing Pharma / Health Care Retail ...

  9. org.hibernate.PropertyAccessException: Null value was assigned to a property of primitive type setter of com.trs.om.bean.User.retryCount

    六月 29, 2019 5:42:45 下午 org.apache.catalina.core.AprLifecycleListener init信息: The APR based Apache To ...

  10. hdu4267 线段树

    开始敲了一发线段树,觉得可以暴力一点的过,tle了.后来进行修改,发现了问题. 后来一看大神的做法,由于1<=k<=10,所以对于不同的k,有55个余,找答案的时候只要找不同的k值满足条件 ...