日韩av黄I国产麻豆传媒I国产91av视频在线观看I日韩一区二区三区在线看I美女国产在线I麻豆视频国产在线观看I成人黄色短片

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 >

【计蒜客 - 2019南昌邀请赛网络赛 - H】Coloring Game(找规律,思维dp)

發布時間:2023/12/10 33 豆豆
生活随笔 收集整理的這篇文章主要介紹了 【计蒜客 - 2019南昌邀请赛网络赛 - H】Coloring Game(找规律,思维dp) 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

題干:

David has a white board with?2 \times N2×N?grids.He decides to paint some grids black with his brush.He always starts at the top left corner and ends at the bottom right corner, where grids should be black ultimately.

Each time he can move his brush up(↑), down(↓), left(←), right(→), left up(↖), left down(↙), right up(↗), right down (↘) to the next grid.

For a grid visited before,the color is still black. Otherwise it changes from white to black.

David wants you to compute the number of different color schemes for a given board. Two color schemes are considered different if and only if the color of at least one corresponding position is different.

Input

One line including an integer?n(0<n \le 10^9)n(0<n≤109)

Output

One line including an integer, which represent the answer?\bmod 1000000007mod1000000007

樣例輸入1復制

2

樣例輸出1復制

4

樣例解釋1

?

樣例輸入2復制

3

樣例輸出2復制

12

樣例解釋2

題目大意:

? ?本身是2*N的白色格子,你從左上角開始走到右下角,每次可以往八個方向走,問你可以踩出多少種本質不同的圖案來。

解題報告

? ?不難發現如果要走到后面,那么中間的任何一列都要被踩到。所以對于每一列,可以踩上 下 上下? 這三種選擇,在加上首尾兩列的四種選擇,所以答案就是? 4*3^(n-2)。

AC代碼:

#include<cstdio> #include<iostream> #include<algorithm> #include<queue> #include<map> #include<vector> #include<set> #include<string> #include<cmath> #include<cstring> #define F first #define S second #define ll long long #define pb push_back #define pm make_pair using namespace std; typedef pair<int,int> PII; const int MAX = 2e5 + 5; const ll mod = 1000000007; ll n; ll qpow(ll a,ll k) {ll res = 1;while(k) {if(k&1) res =(res*a)%mod;a=(a*a)%mod;k>>=1;}return res%mod; } int main() {cin>>n;if(n == 1) printf("1\n");else if(n == 2) printf("4\n");else {ll ans = qpow(3,n-2);ans = ans*4;printf("%lld\n",ans%mod);}return 0 ; }

?

總結

以上是生活随笔為你收集整理的【计蒜客 - 2019南昌邀请赛网络赛 - H】Coloring Game(找规律,思维dp)的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。