1. 程式人生 > >【比賽】NOIP2018 填數遊戲

【比賽】NOIP2018 填數遊戲

c++ com rst first void pri freopen end !=

技術分享圖片

技術分享圖片

技術分享圖片

打表找規律。。。。

#include<bits/stdc++.h>
#define ui unsigned int
#define ll long long
#define db double
#define ld long double
#define ull unsigned long long
#define ft first
#define sd second
#define pb(a) push_back(a)
#define mp(a,b) std::make_pair(a,b)
#define REP(a,b,c) for(register int a=(b),a##end=(c);a<=a##end;++a)
#define DEP(a,b,c) for(register int a=(b),a##end=(c);a>=a##end;--a)
const int Mod=1e9+7;
int n,m,equal[9]={0,0,12,112,912,7136,56768,453504,3626752},start[9]={0,0,36,336,2688,21312,170112,1360128,10879488};
template<typename T> inline void read(T &x)
{
    T data=0,w=1;
    char ch=0;
    while(ch!='-'&&(ch<'0'||ch>'9'))ch=getchar();
    if(ch=='-')w=-1,ch=getchar();
    while(ch>='0'&&ch<='9')data=((T)data<<3)+((T)data<<1)+(ch^'0'),ch=getchar();
    x=data*w;
}
template<typename T> inline void write(T x,char ch='\0')
{
    if(x<0)putchar('-'),x=-x;
    if(x>9)write(x/10);
    putchar(x%10+'0');
    if(ch!='\0')putchar(ch);
}
template<typename T> inline bool chkmin(T &x,T y){return y<x?(x=y,true):false;}
template<typename T> inline bool chkmax(T &x,T y){return y>x?(x=y,true):false;}
template<typename T> inline T min(T x,T y){return x<y?x:y;}
template<typename T> inline T max(T x,T y){return x>y?x:y;}
inline ll qexp(ll a,ll b)
{
    ll res=1;
    while(b)
    {
        if(b&1)res=res*a%Mod;
        a=a*a%Mod;
        b>>=1;
    }
    return res;
}
int main()
{
    freopen("game.in","r",stdin);
    freopen("game.out","w",stdout);
    read(n);read(m);
    if(n>m)std::swap(n,m);
    if(n==1)write(qexp(2,m),'\n');
    else if(n==m)printf("%d\n",equal[n]);
    else printf("%lld\n",1ll*start[n]*qexp(3,m-n-1)%Mod);
    return 0;
}

【比賽】NOIP2018 填數遊戲