【计蒜客 - 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復(fù)制
2樣例輸出1復(fù)制
4樣例解釋1
?
樣例輸入2復(fù)制
3樣例輸出2復(fù)制
12樣例解釋2
題目大意:
? ?本身是2*N的白色格子,你從左上角開(kāi)始走到右下角,每次可以往八個(gè)方向走,問(wèn)你可以踩出多少種本質(zhì)不同的圖案來(lái)。
解題報(bào)告
? ?不難發(fā)現(xiàn)如果要走到后面,那么中間的任何一列都要被踩到。所以對(duì)于每一列,可以踩上 下 上下? 這三種選擇,在加上首尾兩列的四種選擇,所以答案就是? 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)的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: 华为启动鸿蒙开发者大赛 奖金高达100万
- 下一篇: 【HDU - 5922】Minimum’