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 ...
随机推荐
- 【LeetCode】12 & 13 - Integer to Roman & Roman to Integer
12 - Integer to Roman Given an integer, convert it to a roman numeral. Input is guaranteed to be wit ...
- UDP模式与TCP模式的区别
1.TCP有连接状态,而UDP没有. 2.TCP应用层使用无需考虑包的大小及发送情况,而UDP需要. 3.TCP中IP包大小的决定者是Socket,而UDP为应用层.
- 通知(Toast+Notification)
Toast简要说明:(前面已经用过好多次了) Toast是一种非持久的(在屏幕上面留一会儿就消失了),提供给用户简洁提示信息的视图. 它不阻断用户的操作,一般用于显示一些不重要的信息.(比方说设置音量 ...
- 为什么要Cssreset
1.CssReset是什么?由于html标签在各浏览器的默认样式解析出来的有所不同.例如<ul>标签在IE.firefox.chrome浏览器下默认边距是不一样的.各浏览器的默认样,会给我 ...
- Mysql字符串截取函数SUBSTRING的用法说明
感觉上MySQL的字符串函数截取字符,比用程序截取(如PHP或JAVA)来得强大,所以在这里做一个记录,希望对大家有用. 函数: 1.从左开始截取字符串 left(str, length) 说明:le ...
- 记录一下JS正则的坑
JS正则的单行模式有点问题 总之 . 符号匹配换行符号会有问题 暂时的解决方案是 html = html.replace(/[\r\n]/g,""); 附加一个 html = ht ...
- [WinForm] 使用 WebBrowser 操作 HTML 頁面的 Element-摘自网络
前言 在 Window Form 應用程式如果需要瀏覽網頁時可以崁入 WebBrowser 控制項,但如果需要操作崁入的 HTML 的網頁元素,就需要額外的操作,以下紀錄幾種操作 HTML 元素的方法 ...
- 【360开源】thinkjs:基于Promise的Node.js MVC框架 (转)
thinkjs是360奇舞团开源的一款Node.js MVC框架,该框架底层基于Promise来实现,很好的解决了Node.js里异步回调的问题.360奇舞团(奇虎75Team),是奇虎360公司We ...
- openstack network
- XSS攻击及防御(转)
add by zhj: 略有修改.另外还有一篇文章值得参考,使用 PHP 构建的 Web 应用如何避免 XSS 攻击,总得来说防御XSS的方法是客户端和服务端都 要对输入做检查,如果只有客户端做检查, ...