POJ 3734】的更多相关文章

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…
ゲート 分析:这题过的人好多,然后大家好像是用矩阵过的(((φ(◎ロ◎;)φ))).我自己是推公式的. 对于任意的有这个式子, 就是先从里面选偶数个涂成两个指定的颜色,再在选出的里面选定涂某种颜色,选剩下的在剩下的两种颜色里任选.注意两种指定颜色都不选是特殊情况.式子化简下来是. 代码: /*****************************************************/ //#pragma comment(linker, "/STACK:1024000000,1024…
题目链接 题意:有一排砖,可以染红蓝绿黄四种不同的颜色,要求红和绿两种颜色砖的个数都是偶数,问一共有多少种方案,结果对10007取余. 题解:刚看这道题第一感觉是组合数学,正向推了一会还没等推出来队友就打表找到公式了,然后我就写了一个快速幂加个费马小定理就过了去看别的题了,赛后找到了一个很不错的博客:传送门,原来这道题也可以用DP+矩阵快速幂AC.下面说下组合数学的做法: 首先一共有4^n种情况,我们减去不符合条件的情况就行了,从中取k个进行染红绿色一共C(n,k)种情况,剩下的蓝黄色一共有2^…
题目原意:N个方块排成一列,每个方块可涂成红.蓝.绿.黄.问红方块和绿方块都是偶数的方案的个数. sol:找规律列递推式+矩阵快速幂 设已经染完了i个方块将要染第i+1个方块. a[i]=1-i方块中,红.绿方块数量都是偶数的方案数 b[i]=1-i方块中,红.绿方块数量一个是偶数一个是奇数的方案数(红even绿odd 或 红odd绿even) c[i]=1-i方块中,红.绿方块数量都是奇数的方案数 可以得出递推公式: a[i+1]=2*a[i]+b[i] b[i+1]=2*a[i]+2*b[i…
题目的大意: 给定待粉刷的n个墙砖(排成一行),每一个墙砖能够粉刷的颜色种类为:红.蓝.绿.黄, 问粉刷完成后,红色墙砖和蓝色墙砖都是偶数的粉刷方式有多少种(结果对10007取余). 解题思路: 思路用的是递推.如果粉刷到第i个墙砖时,使用的红色墙砖和蓝色墙砖都是偶数的方案 数有ai,使用的红色和蓝色墙砖一奇一偶的方案数为bi,使用的红色和蓝色墙砖都是奇数的 方案数为ci,那么,我们easy得到以下的递推式: 看到上式,对于学过线代的人来说一定不陌生,我们能够将其写成矩阵的形式,然后会发现该 递…
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…
N个方块排成一列 用红,蓝,绿,黄4种颜色去涂色,求红色方块 和绿色方块个数同时为偶数的 方案数 对10007取余 Sample Input 212Sample Output 2//(蓝,黄)6//(红红,蓝蓝,蓝黄,绿绿,黄蓝,黄黄) # include <iostream> # include <cstdio> # include <cstring> # include <algorithm> # include <map> # includ…
题目链接 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…
题意:一排n长度的砖,有四种颜色,红色绿色是偶数,有少染色方式. 分析: 泰勒展开式: chx = (e^x+e^(-x))/2 = 1 + x^2/2! + x^4/4! + x^6/6! + ... ...shx = (e^x-e^(-x))/2 = x + x^3/3! + x^5/5! + x^7/7! + ... ...…
题意:个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…
原题如下: 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…
先从最基础的矩阵快速幂加速递推开始. HDU 1005 Number Sequence |f[n-2],f[n-1]|* |0 B| =|f[n-1], B*f[n-2]+A*f[n-1]|=|f[n-1],f[n]|   |1 A| 建立矩阵如上然后利用快速幂求解即可.答案是mat[0][1]. #include<iostream> #include<vector> #include<cmath> #include<map> #include<alg…
Halloween treats Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 7644   Accepted: 2798   Special Judge Description Every year there is the same problem at Halloween: Each neighbour is only willing to give a certain total number of sweets…
Find a multiple Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 7192   Accepted: 3138   Special Judge Description The input contains N natural (i.e. positive integer) numbers ( N <= 10000 ). Each of that numbers is not greater than 15000…
The Pilots Brothers' refrigerator Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 22286   Accepted: 8603   Special Judge Description The game “The Pilots Brothers: following the stripy elephant” has a quest where a player needs to open a…
Flip Game Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 37427   Accepted: 16288 Description Flip game is played on a rectangular 4x4 field with two-sided pieces placed on each of its 16 squares. One side of each piece is white and the…
Corn Fields Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 9806   Accepted: 5185 Description Farmer John has purchased a lush new rectangular pasture composed of M by N (1 ≤ M ≤ 12; 1 ≤ N ≤ 12) square parcels. He wants to grow some yumm…
Sum of Consecutive Prime Numbers Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 20050   Accepted: 10989 Description Some positive integers can be represented by a sum of one or more consecutive prime numbers. How many such representatio…
Tree Recovery Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 11939   Accepted: 7493 Description Little Valentine liked playing with binary trees very much. Her favorite game was constructing randomly looking binary trees with capital le…
Seek the Name, Seek the Fame Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 17898   Accepted: 9197 Description The little cat is so famous, that many couples tramp over hill and dale to Byteland, and asked the little cat to give names t…
题目: poj 2352 Stars 数星星 题意:已知n个星星的坐标.每个星星都有一个等级,数值等于坐标系内纵坐标和横坐标皆不大于它的星星的个数.星星的坐标按照纵坐标从小到大的顺序给出,纵坐标相同时则按照横坐标从小到大输出. (0 <= x, y <= 32000) 要求输出等级0到n-1之间各等级的星星个数. 分析: 这道题不难想到n平方的算法,即从纵坐标最小的开始搜,每次找它前面横坐标的值比它小的点的个数,两个for循环搞定,但是会超时. 所以需要用一些数据结构去优化,主要是优化找 横坐…
poj   1251  Jungle Roads  (最小生成树) Link: http://poj.org/problem?id=1251 Jungle Roads Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 23507   Accepted: 11012 Description The Head Elder of the tropical island of Lagrishan has a problem. A b…
Kaka's Matrix Travels Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 9567   Accepted: 3888 Description On an N × N chessboard with a non-negative number in each grid, Kaka starts his matrix travels with SUM = 0. For each travel, Kaka mo…
Friendship Time Limit: 2000MS   Memory Limit: 20000K Total Submissions: 10626   Accepted: 2949 Description In modern society, each person has his own friends. Since all the people are very busy, they communicate with each other only by phone. You can…
Ikki's Story I - Road Reconstruction Time Limit: 2000MS   Memory Limit: 131072K Total Submissions: 7659   Accepted: 2215 Description Ikki is the king of a small country – Phoenix, Phoenix is so small that there is only one city that is responsible fo…
http://poj.org/problem?id=1144 题意:给你一些点,某些点直接有边,并且是无向边,求有多少个点是割点 割点:就是在图中,去掉一个点,无向图会构成多个子图,这就是割点 Tarjan算法求割点的办法 如果该点为根,那么它的子树必须要大于1 如果该点不为根,那么当low[v]>=dnf[u]时,为割点 Low[v]>=dnf[u]也就是说明U的子孙点只能通过U点访问U的祖先点 #include <stdio.h> #include <stack>…
http://poj.org/problem?id=3614 题意:有n头奶牛想要晒太阳,但他们每个人对太阳都有不同的耐受程度,也就是说,太阳不能太大也不能太小,现在有一种防晒霜,涂抹这个防晒霜可以把太阳的强度固定到一个值 求一共有多少头奶牛可以晒太阳 #include <stdio.h> #include <queue> #include <stdlib.h> using namespace std; int m,n; struct co{ int mi,ma; }c…