原题链接:http://codeforces.com/gym/100338/attachments/download/2136/20062007-winter-petrozavodsk-camp-andrew-stankevich-contest-22-asc-22-en.pdf

题意

给你n个点,让你连边,使得每个点的度至少为1,问你方案数。

题解

从正面考虑非常困难,应从反面考虑,取 i 点出来不连,这样的取法一共有C(n,i)种取法,其他的连好,而这样就是子问题了。那么dp[n]=2^(n*(n-1)/2)-sum(C(n,i)*dp[n-i])-1,2<=i<=n-1

代码

import java.io.File;
import java.io.FileNotFoundException;
import java.io.PrintWriter;
import java.math.BigInteger;
import java.util.*; public class Main {
static int n;
static BigInteger dp[] = new BigInteger[110];
static BigInteger c[][] = new BigInteger[110][110];
static BigInteger ps[] = new BigInteger[10010];
static BigInteger x;
public Main() throws FileNotFoundException{
Scanner cin = new Scanner(new File("trains.in"));
PrintWriter cout = new PrintWriter(new File("trains.out"));
n = cin.nextInt();
//System.out.println("n = " + n);
for(int i=1;i<=100;i++){
c[i][0] = new BigInteger("1");
c[i][1] = new BigInteger(Integer.toString(i));
c[i][i] = new BigInteger("1");
}
for(int i=2;i<=100;i++){
for(int j=2;j<i;j++){
c[i][j] = c[i-1][j].add(c[i-1][j-1]);
}
}
ps[0] = new BigInteger("1");
for(int i=1;i<=10001;i++){
ps[i] = ps[i-1].multiply(new BigInteger("2"));
}
dp[2] = new BigInteger("1");
dp[3] = new BigInteger("4");
for(int i=4;i<=n;i++){
x = new BigInteger("0");
for(int j=2;j<=i-1;j++){
x = x.add(c[i][i-j].multiply(dp[j]));
}
x = x.add(new BigInteger("1"));
dp[i] = ps[i*(i-1)/2].subtract(x);
}
cout.println(dp[n]);
//System.out.println(dp[n]);
cin.close();
cout.close();
} public static void main(String[] args) throws FileNotFoundException {
new Main();
}
}

Codeforces Gym 100338H High Speed Trains 组合数学+dp+高精度的更多相关文章

  1. codeforces Gym 100338H High Speed Trains (递推,高精度)

    递推就好了,用二项式定理算出所有连边的方案数,减去不合法的方案, 每次选出一个孤立点,那么对应方案数就是上次的答案. 枚举选几个孤立点和选哪些,选到n-1个点的时候相当于都不选,只减1. 要用到高精度 ...

  2. Codeforces Gym 100342D Problem D. Dinner Problem Dp+高精度

    Problem D. Dinner ProblemTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/1003 ...

  3. Codeforces Gym 100002 Problem F "Folding" 区间DP

    Problem F "Folding" Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/ ...

  4. codeforces 869C The Intriguing Obsession【组合数学+dp+第二类斯特林公式】

    C. The Intriguing Obsession time limit per test 1 second memory limit per test 256 megabytes input s ...

  5. Codeforces Gym 100431B Binary Search 搜索+组合数学+高精度

    原题链接:http://codeforces.com/gym/100431/attachments/download/2421/20092010-winter-petrozavodsk-camp-an ...

  6. Codeforces #144 (Div. 1) B. Table (组合数学+dp)

    题目链接: B.Table 题意: \(n*m\)的矩阵使每个\(n*n\)矩阵里面准确包含\(k\)个点,问你有多少种放法. \((1 ≤ n ≤ 100; n ≤ m ≤ 10^{18}; 0 ≤ ...

  7. Codeforces gym 101343 J.Husam and the Broken Present 2【状压dp】

     2017 JUST Programming Contest 2.0 题目链接:Codeforces gym 101343 J.Husam and the Broken Present 2 J. Hu ...

  8. Codeforces 219D. Choosing Capital for Treeland (树dp)

    题目链接:http://codeforces.com/contest/219/problem/D 树dp //#pragma comment(linker, "/STACK:10240000 ...

  9. Codeforces Gym 101252D&&floyd判圈算法学习笔记

    一句话题意:x0=1,xi+1=(Axi+xi%B)%C,如果x序列中存在最早的两个相同的元素,输出第二次出现的位置,若在2e7内无解则输出-1. 题解:都不到100天就AFO了才来学这floyd判圈 ...

随机推荐

  1. 第6章 AOP与全局异常处理6.5-6.11 慕课网微信小程序开发学习笔记

    https://coding.imooc.com/learn/list/97.html 目录: 第6章 AOP与全局异常处理6-1 正确理解异常处理流程 13:236-2 固有的处理异常的思维模式与流 ...

  2. 常用排序算法的总结以及编码(Java实现)

    常用排序算法的总结以及编码(Java实现) 本篇主要是总结了常用算法的思路以及相应的编码实现,供复习的时候使用.如果需要深入进行学习,可以使用以下两个网站: GeeksForGeeks网站用于学习相应 ...

  3. COMP9021--6.17

    1. ''' '''the comment in the middle will be shown in your code while ranning 2. a=bc=a%bor we can si ...

  4. Python json和simplejson的使用

    在Python中,json数据和字符串的转换可以使用json模块或simplejson模块. json从Python2.6开始内置到了Python标准库中,我们不需要安装即可直接使用. simplej ...

  5. aoj-0118 property distribution(搜索)

    Time limit1000 ms Memory limit131072 kB タナカ氏が HW アールの果樹園を残して亡くなりました.果樹園は東西南北方向に H × Wの区画に分けられ.区画ごとにリ ...

  6. jmeter进行dubbo接口测试

    最近工作中接到一个需求,需要对一个MQ消息队列进行性能测试,测试其消费能力,开发提供了一个dubbo服务来供我调用发送消息. 这篇博客,介绍下如何利用jmeter来测试dubbo接口,并进行性能测试. ...

  7. ORACLE 分区表 相关视图

    1. 显示当前用户可访问的所有分区表信息﹕ ALL_PART_TABLES 2. 显示当前用户所有分区表的信息﹕ USER_PART_TABLES 3. 显示表分区信息 显示数据库所有分区表的详细分区 ...

  8. Leetcode 435.无重叠区间

    无重叠区间 给定一个区间的集合,找到需要移除区间的最小数量,使剩余区间互不重叠. 注意: 可以认为区间的终点总是大于它的起点. 区间 [1,2] 和 [2,3] 的边界相互"接触" ...

  9. 【Kubernetes】The connection to the server <master>:6443 was refused - did you specify the right host or port?

    不知道怎么用着用着,使用kubectl 时报错,错误如下: root@R740--:~# kubectl get pod The connection to the server 107.105.13 ...

  10. curl保存图片

    $url = 'http://p1.qhimg.com/t013dfc89f8a039122c.jpg?size=690x460'; function http_get_data($url) { $c ...