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;}
}

转载于:https://www.cnblogs.com/qscqesze/p/5135986.html

Codeforces Gym 100015B Ball Painting 找规律相关推荐

  1. CodeForces - Insertion Sort(打表找规律)

    题目链接:http://codeforces.com/gym/101955/problem/C Time limit:6.0 s Memory limit:1024 MB Problem Descri ...

  2. codeforces ECR 74 Standard Free2play(找规律)

    题目大意: 有一座山,山有h层.每一层都有平台.有些平台凸出来,有些平台是凹进去.主角一开始站在h层平台,他的目标是落到第0层.主角能够下山的方式只有一种:让高为x的平台和高为x-1平台的状态取反从而 ...

  3. Celex Update CodeForces - 1358C(打表找规律)

    During the quarantine, Sicromoft has more free time to create the new functions in "Celex-2021& ...

  4. Grid game CodeForces - 1104C 放格子|思维|找规律

    题意:4*4的格子中输入0放 2*1的图案输入1放1*2的图案 当摆满一行或一列后此行列图案清空 就想毛熊方块一样 分析:开始感觉很唬人 要搜索还是要dp啥的 后来发现原来2*1就放左下 1*2就放左 ...

  5. 【CodeForces - 735B】Urbanization (找规律,思维)

    题干: Local authorities have heard a lot about combinatorial abilities of Ostap Bender so they decided ...

  6. Codeforces Round #715 (Div. 1) B. Almost Sorted 找规律

    传送门 文章目录 题意: 思路: 题意: 思路: 找规律yydsyydsyyds. 一看没什么想法,所以打了个表,好家伙,不打不知道,一打不得了,下面是n=6n=6n=6的符合要求的情况: 不难发现, ...

  7. [codeforces 1333A] Little Artem 读懂题+找规律+多举例

    Codeforces Round #632 (Div. 2)   比赛人数12810 [codeforces 1333A]   Little Artem   读懂题+找规律+多举例 总目录详见http ...

  8. [codeforces 1327E] Count The Blocks 打表找规律+根据规律找公式+优化公式

    Educational Codeforces Round 84 (Rated for Div. 2)   比赛人数13522 [codeforces 1327E]  Count The Blocks  ...

  9. Codeforces 959 E. Mahmoud and Ehab and the xor-MST 思路:找规律题,时间复杂度O(log(n))

    题目: 解题思路 这题就是0,1,2-n-1总共n个数字形成的最小生成树. 我们可以发现,一个数字k与比它小的数字形成的异或值,一定可以取到k与所有正整数形成的异或值的最小值. 要计算n个数字的情况我 ...

  10. CodeForces - 603C Lieges of Legendre(博弈+找规律)

    题目链接:点击查看 题目大意:首先给出n堆石子和一个k值,两人轮流按照规则操作,不能操作的一方即为失败,每一次都有两种操作: 从任意一堆石子中取走一个石子 任选一堆偶数个的石子,将其转换成k堆x/2的 ...

最新文章

  1. Anroid基础建设之View,Window,Activity
  2. 如何使用 tf object detection
  3. Java核心技术及面试指南 异常部分的面试题归纳以及答案
  4. 怎么增加服务器容量,新睿云服务器硬盘容量怎么增加?
  5. 大页内存的使用:大页内存分配与释放
  6. 怎样安装ubuntu系统
  7. 关于vim的误删除经历
  8. C语言之编程规范及细节知识(学C必看)
  9. #读书笔记—《自控力》第二章
  10. Matching the Blanks: Distributional Similarity for Relation Learning (通篇翻译)
  11. 苦难是人生最大的财富
  12. bp是什么意思贷款利率,bp在利率是什么意思
  13. ETC/CFX/RVN/NEOXA/ERGO连接地址
  14. 【性能测试】轻商城-项目实战2
  15. [ZZ]:Google 发现的十大真理
  16. 递推算法(以数字三角形为例)
  17. 猿辅导的python课_猿辅导和一课哪个更好?
  18. Unity Anchors锚点布局不出现的原因
  19. rgb sw 线主板接口在哪_个性外观兼容强,还送三风扇,酷冷至尊TD500 MESH体验|机箱|电源|散热器|主板|白色...
  20. sqlserver四舍六入五留双函数

热门文章

  1. HR 问你为什么离职时是什么意思
  2. linux segmentation fault 信号,linux中 Segmentation fault问题
  3. C标准库-va_list
  4. css过度效果及动画效果
  5. 【190222】VC++ 社区视频监控系统源代码
  6. 计算机控制面板属性在哪里打开,win7如何打开系统属性面板|win7打开系统属性面板的方法...
  7. 【Django】第一课 基于Django图书借阅管理网站平台
  8. WINDOWS备份与恢复
  9. 一次失败的Thoughtworks面试经历
  10. yum源及常用安装包整理