日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

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

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

題干:

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復(fù)制

2

樣例輸出1復(fù)制

4

樣例解釋1

?

樣例輸入2復(fù)制

3

樣例輸出2復(fù)制

12

樣例解釋2

題目大意:

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

解題報告

? ?不難發(fā)現(xià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 ; }

?

總結(jié)

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

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。