Anton and School - 2 (组合数学)】的更多相关文章

题意:有一个只有’(‘和’)’的串,可以随意的删除随意多个位置的符号,现在问能构成((((((…((()))))….))))))这种对称的情况有多少种,保证中间对称,左边为’(‘右边为’)’. 析:通过枚举 ‘(’ 来计算有多少种情况,假设 第 i 个括号前面有 n 个 '(',右边有 m 个 ')',那么总共就有 sigma(1, n, C(n-1, i-1)*C(m, i)),其中 1,n 表示从上下限.. 然后这样算的话就是 n 方的复杂度,会超时,再利用范德蒙恒等式(不会的请点击:htt…
题目链接 Anton and School - 2 对于序列中的任意一个单括号对(), 左括号左边(不含本身)有a个左括号,右括号右边(不含本身有)b个右括号. 那么答案就为 但是这样枚举左右的()的话,最快情况复杂度为1e10,TLE. 所以对于每个左括号,把他右边的所有右括号一起来考虑. 对于每个左括号,令它左边(不含它本身)括号数位x,它右边右括号数位y. 那么当前答案为     复杂度O(Nlogmod),其中mod=1e9+7. PS:代码中的这个y应该是上图的y-1.   #incl…
题意:给你一串只有‘(’与‘)’的字符串,问你多少对括号,括号一定是左边一半的‘(’,右边一半是‘)’ )(()()   答案是:6 题解:枚举每个‘(’,此时设左括号左边有n个‘(’,它右边有m个‘)’,当我们设定此时的‘(’一定选定时,就不会重复了 然后对于每个位置我们就可以推出这样的公式:注意‘)’一定需要一个,且如果n<m则大于m的部分没有意义 接着我们有范德蒙恒等式: 我们可以这样理解:在m个人中选择i个,n个人选择k-i个人,则我们可以表示在m+n个人中选择k个人 接着我们将原来的公…
E. Anton and Tree time limit per test: 3 seconds memory limit per test :256 megabytes input:standard input output: standard output Anton is growing a tree in his garden. In case you forgot, the tree is a connected acyclic undirected graph. There are …
题目链接 题意:有一排砖,可以染红蓝绿黄四种不同的颜色,要求红和绿两种颜色砖的个数都是偶数,问一共有多少种方案,结果对10007取余. 题解:刚看这道题第一感觉是组合数学,正向推了一会还没等推出来队友就打表找到公式了,然后我就写了一个快速幂加个费马小定理就过了去看别的题了,赛后找到了一个很不错的博客:传送门,原来这道题也可以用DP+矩阵快速幂AC.下面说下组合数学的做法: 首先一共有4^n种情况,我们减去不符合条件的情况就行了,从中取k个进行染红绿色一共C(n,k)种情况,剩下的蓝黄色一共有2^…
题目传送门 /* 题意:从前面找一个数字和末尾数字调换使得变成偶数且为最大 贪心:考虑两种情况:1. 有偶数且比末尾数字大(flag标记):2. 有偶数但都比末尾数字小(x位置标记) 仿照别人写的,再看自己的代码发现有清晰的思维是多重要 */ #include <cstdio> #include <iostream> #include <algorithm> #include <cmath> #include <cstring> #include…
E. Anton and Tree 题目连接: http://codeforces.com/contest/734/problem/E Description Anton is growing a tree in his garden. In case you forgot, the tree is a connected acyclic undirected graph. There are n vertices in the tree, each of them is painted bla…
D. Anton and Chess 题目连接: http://codeforces.com/contest/734/problem/D Description Anton likes to play chess. Also, he likes to do programming. That is why he decided to write the program that plays chess. However, he finds the game on 8 to 8 board to…
C. Anton and Making Potions 题目连接: http://codeforces.com/contest/734/problem/C Description Anton is playing a very interesting computer game, but now he is stuck at one of the levels. To pass to the next level he has to prepare n potions. Anton has a…
B. Anton and Digits 题目连接: http://codeforces.com/contest/734/problem/B Description Recently Anton found a box with digits in his room. There are k2 digits 2, k3 digits 3, k5 digits 5 and k6 digits 6. Anton's favorite integers are 32 and 256. He decide…