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 找规律的更多相关文章

  1. Codeforces Gym 100637B B. Lunch 找规律

    B. Lunch Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100637/problem/B Des ...

  2. 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 ...

  3. Codeforces 870C Maximum splitting (贪心+找规律)

    <题目链接> 题目大意: 给定数字n,让你将其分成合数相加的形式,问你最多能够将其分成几个合数相加. 解题分析: 因为要将其分成合数相加的个数最多,所以自然是尽可能地将其分成尽可能小的合数 ...

  4. Gym - 101775L SOS 博弈 找规律

    题目:https://cn.vjudge.net/problem/Gym-101775L PS:训练赛中被这道题折磨的不轻,和队友反复推必胜态与必败态试图推导出公式或者规律,然后推的心态逐渐失控,,, ...

  5. hdoj 2277 Change the ball【找规律】

    Change the ball Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)T ...

  6. Change the ball(找规律)

    Change the ball Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)T ...

  7. Codeforces 603A - Alternative Thinking - [字符串找规律]

    题目链接:http://codeforces.com/problemset/problem/603/A 题意: 给定一个 $01$ 串,我们“交替子序列”为这个串的一个不连续子序列,它满足任意的两个相 ...

  8. Gym 100962G Green Day (找规律)

    题意:你用k 个生成树构成一个完全图. 析:n 个点的完全图有n(n-1)/2个边,一个生成树有n-1个边,你有k 个生成树 即边数等于 K(n-1) ,即  n(n-1)/2 == k(n-1)   ...

  9. Codeforces 474D Flowers (线性dp 找规律)

    D. Flowers time limit per test:1.5 seconds memory limit per test:256 megabytes We saw the little gam ...

随机推荐

  1. 独立开发游戏越来越容易:Unity 发布旗下的最新游戏引擎 Unity 5,依然有免费版(转)

    独立开发者开发游戏正变得越来越容易,因为在游戏设计中很多吃力不讨好的工作可以直接采用像 Epic Games 或 Unity Technologies 这样的游戏引擎来解决.而这几天,游戏引擎商们先后 ...

  2. cocos2d-x CocoStudio中场景触发器(Trigger)的使用和扩展

    场景编辑器中的触发器是一种通过事件触发机制,在特定的事件被触发的时候自动执行自己预先定义的动作或者功能. 编辑器中带有一些默认的事件.条件和动作,当然也可以扩展自定义的事件.条件和动作. 触发器可以创 ...

  3. 转-问自己:UI设计注意的十个问题

    UI 设计需要自问的 10个问题   UI 设计的魅力在于,你不仅需要适当的技巧,更要理解用户与程序的关系.一个有效的用户界面关注的是用户目标的实现,包括视觉元素与功能操作在内的所有东西都需要完整一致 ...

  4. 60个响应式的Web设计教程–能够手机访问!

    想要学习响应式[responsive:屏幕自适应的效果]的网页设计和开发技术?在这个超大的收藏集合中,我想你定会找到想要开始学习的响应式网页设计教程. 面对超过1亿的手机互联网用户,开发专业和用户友好 ...

  5. cocos中添加显示文字的三种方式(CCLabelTTF 、CCLabelBMFont 和CCLabelAtlas)

    CCLabelTTF CCLabelTTF 每次调用 setString (即改变文字)的时候,一个新的OPENGL 纹理将会被创建..这意味着setString 和创建一个新的标签一样慢. 这个类使 ...

  6. DataGrid loadData loadFilter

    <!DOCTYPE html><html><head> <meta charset="UTF-8"> <title>Cl ...

  7. java.io.IOException: Messenger was closed

    程序运行一段时间后抛出异常java.io.IOException: Messenger was closed,不知道是啥原因? ———————————————————————————————————— ...

  8. 用c++库函数轻松解决回文问题

    在<Accelerated C++>6.1学到的,这个解决回文问题的方案很简单,有必要把它记录下来. begin返回一个迭代器,它会从容器的最后一个元素开始,并且从后向前地逆序访问容器.e ...

  9. C#中字符串与byte[]相互转换

    字符串转换为byte[] 给定一个string,转换为byte[],有以下几种方法. 方法1: static byte[] GetBytes(string str) { byte[] bytes = ...

  10. Samsung Galaxy S II GT-I9100 指令全集 部分指令请慎用

    英文版 谷歌翻译 Obtain/Change Device Information *#06# (Display IMEI number) *#1234# (Display current firmw ...