Blocks(POJ 3734)】的更多相关文章

原题如下: Blocks Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 8020   Accepted: 3905 Description Panda has received an assignment of painting a line of blocks. Since Panda is such an intelligent boy, he starts to think of a math problem of…
Blocks Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 3997   Accepted: 1775 Description Panda has received an assignment of painting a line of blocks. Since Panda is such an intelligent boy, he starts to think of a math problem of paint…
Blocks Input The first line of the input contains an integer T(1≤T≤100), the number of test cases. Each of the next T lines contains an integer N(1≤N≤10^9) indicating the number of blocks. Output For each test cases, output the number of ways to pain…
题目链接 Description Panda has received an assignment of painting a line of blocks. Since Panda is such an intelligent boy, he starts to think of a math problem of painting. Suppose there are N blocks in a line and each block can be paint red, blue, gree…
ゲート 分析:这题过的人好多,然后大家好像是用矩阵过的(((φ(◎ロ◎;)φ))).我自己是推公式的. 对于任意的有这个式子, 就是先从里面选偶数个涂成两个指定的颜色,再在选出的里面选定涂某种颜色,选剩下的在剩下的两种颜色里任选.注意两种指定颜色都不选是特殊情况.式子化简下来是. 代码: /*****************************************************/ //#pragma comment(linker, "/STACK:1024000000,1024…
题目链接 题意:有一排砖,可以染红蓝绿黄四种不同的颜色,要求红和绿两种颜色砖的个数都是偶数,问一共有多少种方案,结果对10007取余. 题解:刚看这道题第一感觉是组合数学,正向推了一会还没等推出来队友就打表找到公式了,然后我就写了一个快速幂加个费马小定理就过了去看别的题了,赛后找到了一个很不错的博客:传送门,原来这道题也可以用DP+矩阵快速幂AC.下面说下组合数学的做法: 首先一共有4^n种情况,我们减去不符合条件的情况就行了,从中取k个进行染红绿色一共C(n,k)种情况,剩下的蓝黄色一共有2^…
题意:个n个方块涂色, 只能涂红黄蓝绿四种颜色,求最终红色和绿色都为偶数的方案数. 该题我们可以想到一个递推式 .   设a[i]表示到第i个方块为止红绿是偶数的方案数, b[i]为红绿恰有一个是偶数的方案数, c[i]表示红绿都是奇数的方案数. 那么有如下递推可能: 递推a[i+1]:1.到第i个为止都是偶数,且第i+1个染成蓝或黄:2.到第i个为止红绿恰有一个是奇数,并且第i+1个方块染成了奇数对应的颜色. 递推b[i+1]:1.到第i个为止都是偶数,且第i+1个染成红或绿:2.到第i个为止…
定义ai表示红色和绿色方块中方块数为偶数的颜色有i个,i = 0,1,2. aij表示刷到第j个方块时的方案数,这是一个线性递推关系. 可以构造递推矩阵A,用矩阵快速幂求解. /********************************************************* * ------------------ * * author AbyssalFish * *********************************************************…
指数型生成函数,推一推可得: \[ (1+\frac{x^1}{1!}+\frac{x^2}{2!}+\frac{x^3}{3!}+...)^2+(1+\frac{x^2}{2!}+\frac{x^4}{4!}+\frac{x^6}{6!}+...)^2 \] \[ =e^{2x}+(\frac{e^x+2^-x}{2})^2 \] \[ =e^{2x}+\frac{e^{2x}+e^{-2x}+2}{4} \] \[ =\frac{e^{4x}+2e^{2x}+1}{4} \] 因为 \[ e…
POJ3734 比较简单的递推题目,只需要记录当前两种颜色均为偶数, 只有一种颜色为偶数 两种颜色都为奇数 三个数量即可,递推方程相信大家可以导出. 最后来个快速幂加速即可. #include<cstdio> #include<cstdlib> #include<cstring> #include<cmath> #include<vector> #include<queue> #include<stack> #includ…