Codeforces Gym 100015B Ball Painting 找规律
Ball Painting
题目连接:
http://codeforces.com/gym/100015/attachments
Description
There are 2N white balls on a table in two rows, making a nice 2-by-N rectangle. Jon has a big paint bucket
full of black paint. (Don’t ask why.) He wants to paint all the balls black, but he would like to have some
math fun while doing it. (Again, don’t ask why.) First, he computed the number of di!erent ways to paint
all the balls black. In no time, he figured out that the answer is (2N)! and thought it was too easy. So, he
introduced some rules to make the problem more interesting.
• The first ball that Jon paints can be any one of the 2N balls.
• After that, each subsequent ball he paints must be adjacent to some black ball (that was already
painted). Two balls are assumed to be adjacent if they are next to each other horizontally, vertically,
or diagonally.
Jon was quite satisfied with the rules, so he started counting the number of ways to paint all the balls
according to them. Can you write a program to find the answer faster than Jon?
Input
The input consists of multiple test cases. Each test case consists of a single line containing an integer N,
where 1 ! N ! 1,000. The input terminates with a line with N = 0. For example:
1
2
3
0
Output
For each test case, print out a single line that contains the number of possible ways that Jon can paint all
the 2N balls according to his rules. The number can become very big, so print out the number modulo
1,000,000,007. For example, the correct output for the sample input above would be:
2
24
480
Sample Input
1
2
3
0
Sample Output
2
24
480
Hint
题意
给你2*n的矩阵,都是白色
1.一开始你随便选一个染成黑色
2.接下来你可以选择一个和黑色相邻的白色,染成黑色
问你有多少种染法
题解:
我是OEIS的,蛤蛤
正常做可以DP
代码
#include<bits/stdc++.h>
using namespace std;
const int mod = 1e9+7;
//(4-8*n)*a(n)+a(n+1) =0.
long long a[1200];
void pre()
{
a[1]=1;
a[2]=2;
for(int i=3;i<=1100;i++)
a[i]=(a[i-1]*(8LL*(i-1LL)-4LL))%mod;
}
long long n;
int main()
{
pre();
while(cin>>n)
{
if(n==0)break;
cout<<a[n+1]<<endl;
}
}
Codeforces Gym 100015B Ball Painting 找规律的更多相关文章
- Codeforces Gym 100637B B. Lunch 找规律
B. Lunch Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100637/problem/B Des ...
- codeforces B. A and B 找规律
Educational Codeforces Round 78 (Rated for Div. 2) 1278B - 6 B. A and B time limit per test 1 secon ...
- Codeforces 870C Maximum splitting (贪心+找规律)
<题目链接> 题目大意: 给定数字n,让你将其分成合数相加的形式,问你最多能够将其分成几个合数相加. 解题分析: 因为要将其分成合数相加的个数最多,所以自然是尽可能地将其分成尽可能小的合数 ...
- Gym - 101775L SOS 博弈 找规律
题目:https://cn.vjudge.net/problem/Gym-101775L PS:训练赛中被这道题折磨的不轻,和队友反复推必胜态与必败态试图推导出公式或者规律,然后推的心态逐渐失控,,, ...
- hdoj 2277 Change the ball【找规律】
Change the ball Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)T ...
- Change the ball(找规律)
Change the ball Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)T ...
- Codeforces 603A - Alternative Thinking - [字符串找规律]
题目链接:http://codeforces.com/problemset/problem/603/A 题意: 给定一个 $01$ 串,我们“交替子序列”为这个串的一个不连续子序列,它满足任意的两个相 ...
- Gym 100962G Green Day (找规律)
题意:你用k 个生成树构成一个完全图. 析:n 个点的完全图有n(n-1)/2个边,一个生成树有n-1个边,你有k 个生成树 即边数等于 K(n-1) ,即 n(n-1)/2 == k(n-1) ...
- Codeforces 474D Flowers (线性dp 找规律)
D. Flowers time limit per test:1.5 seconds memory limit per test:256 megabytes We saw the little gam ...
随机推荐
- 4. 2D绘制与控件绘制
绘制基本图形和文本 绘制图形和文本的基本方法 drawPoint(绘制点).drawLine(绘制直线).drawCircle(绘制圆) drawArc(绘制弧).drawText(绘制文本) pac ...
- bjfu1299 stl使用
题目超简单,我写解题报告是因为我的代码用了些STL,使代码很简洁. * * Author : ben */ #include <cstdio> #include <cstdlib&g ...
- IDEA14 Ultimate Edition注册码
分享几个license: (1) key:IDEA value:61156-YRN2M-5MNCN-NZ8D2-7B4EW-U12L4 (2) key:huangweivalue:97493-G3A4 ...
- TCP经受时延的ACK
下午看<卷1>的时候,感觉“TCP经受时延ACK”这段看的有些迷糊,最后还算理解了,所以这里记下来以免以后又忘了. 经受时延的ACK就是在接收到数据后不立马确认,而是等到内核的一个定时器到 ...
- 精选PSD素材下载周刊【Goodfav PSD 20130720】
我们每周精选来自Goodfav PSD的免费PSD素材,有兴趣的朋友尤其是做设计工作的,不妨收藏或者下载. 这些现成的PSD素材能给我们一些相关的灵感,从而提高工作的效率. 1.File Upload ...
- Java Web高性能开发(三)
今日要闻: Clarifai:可识别视频中物体 最近几年,得益于深度学习技术的发展,谷歌和Facebook等企业的研究人员在图形识别软件领域取得了重大突破.现在,一家名为Clarifai的创业公司则提 ...
- Hadoop学习记录(7)|Eclipse远程调试Hadoop
1.创建Hadoop项目 2.创建包.类 这里使用hdfs.WordCount为例 3.编写自定Mapper和Reducer程序 MyMapper类 static class MyMapper ext ...
- 【转】Hive导入10G数据的测试
原博文出自于: http://blog.fens.me/hadoop-hive-10g/ 感谢! Hive导入10G数据的测试 让Hadoop跑在云端系列文章,介绍了如何整合虚拟化和Hadoop,让H ...
- 2010“架构师接龙”问答--杨卫华VS赵劼(转)
add by zhj:虽然是几年前的文章,但还是很有参考价值的 原文:http://blog.zhaojie.me/2010/05/programmer-magazine-2010-5-archite ...
- Hibernate入门(2)- 不用配置用注解
在上一个例子里面,我用的配置文件的方式,这次改成注解. pom.xml 增加了hibernate-commons-annotations和hibernate-annotations <proje ...