首页 > 其他分享 >HDU 5434 Peace small elephant

HDU 5434 Peace small elephant

时间:2022-11-09 22:38:12浏览次数:40  
标签:HDU elephants int Peace range elephant small include



Problem Description Xiao Ming likes playing the international chess ,especially like the elephant(it can move by slant while no barrier),

but he think the big elephant of the chess is cruel,and a kind of small elephant is not as cruel as the big elephant.

Its attack range is checks on the ramp of the small elephant's check's right angle.Now Ming is going to put many small elephants on his chessboard.

It's interesting that when two small elephants have a common side they'll become one solidarity elephant,

and more than 2 small elephants also can do this if satisfy the condition,and the attack range of solidarity elephants is same as the small elephant.

Now there is a requirement that it's empty on anyone of elephants' attack range(no piece).Xiao Ming has a special chessboard with  m∗n  checks.

Please figure out the number of all the plans that satisfy the condition.As the number is too big,we need to have a modulo  1000000007 .

The following is pictures show the attack range of elephants with different shape,"X"means attack range.

HDU 5434	 Peace small elephant_其他
 
Input There are at most  5  testcases .

For each testcase contains two integers  n,m  ,meaning as in the title.
1≤n≤1000000000,1≤m≤7
 
Output For each testcase print a single integer - the number of all the plans that satisfy the condition.
 
Sample Input 1 1 2 3  
Sample Output 2 50 递推出矩阵,然后快速幂

#include<map>
#include<cmath>
#include<queue>
#include<stack>
#include<string>
#include<cstdio>
#include<vector>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long LL;
const int maxn = 1000000007;
LL T, n, m, a[128][128], b[128], ans;

bool check(int x, int y)
{
    for (int i = 0; i < n; i++) 
    {
        int k = 1 << i;
        if (x&k)
        {
            if (y&k) continue;
            if ((y >> 1)&k)
            {
                if (!((x >> 1)&k)) return false;
            }
            if ((y << 1)&k)
            {
                if (!((x << 1)&k)) return false;
            }
        }
    }
    return true;
}

void update()
{
    LL c[128][128] = { 0 };
    for (int i = 0; i < (1 << n); i++)
        for (int j = 0; j < (1 << n); j++)
            for (int k = 0; k < (1 << n); k++)
                (c[i][k] += a[i][j] * a[j][k]) %= maxn;
    for (int i = 0; i < (1 << n); i++)
        for (int j = 0; j < (1 << n); j++) a[i][j] = c[i][j];
}

void get()
{
    LL c[128] = { 0 };
    for (int j = 0; j < (1 << n); j++)
        for (int k = 0; k < (1 << n); k++)
            (c[k] += b[j] * a[j][k]) %= maxn;
    for (int i = 0; i < (1 << n); i++) b[i] = c[i];
}

int main()
{
    //scanf("%I64d", &T);
    //while (T--)
    while (scanf("%I64d%I64d", &m, &n) != EOF)
    {
        for (int i = 0; i < (1 << n); i++)
        for (int j = 0; j < (1 << n); j++) if (check(i, j)) a[i][j] = 1; else a[i][j] = 0;
        for (int i = 0; i < (1 << n); i++) b[i] = 1;
        for (int i = m - 1; i; i >>= 1)
        {
            if (i & 1) get();
            update();
        }
        ans = 0;
        for (int i = 0; i < (1 << n); i++) (ans += b[i]) %= maxn;
        printf("%I64d\n", ans);
    }
    return 0;
}


标签:HDU,elephants,int,Peace,range,elephant,small,include
From: https://blog.51cto.com/u_15870896/5838874

相关文章

  • HDU 5442 Favorite Donut
    ProblemDescriptionLuluhasasweettooth.Herfavoritefoodisringdonut.Everydayshebuysaringdonutfromthesamebakery.Aringdonutisconsis......
  • HDU 3518 Boring counting
    Description035nowfacedatoughproblem,hisenglishteachergiveshimastring,whichconsistswithnlowercaseletter,hemustfigureouthowmanysub......
  • HDU 4210 Su-domino-ku
    ProblemDescriptionAsiftherewerenotalreadyenoughsudoku-likepuzzles,theJuly2009issueofGamesMagazinedescribesthefollowingvariantthat......
  • HDU 5722 Jewelry
    ProblemDescriptionAfterallthedifficulties,PsycheandCupidarefinallygettingmarried.NoordinarypearlscanholdCupid'sloveforPsyche.So......
  • HDU 3713 Double Maze
    ProblemDescriptionUnlikesinglemaze,doublemazerequiresacommonsequenceofcommandstosolvebothmazes.Seethefigurebelowforaquickunderst......
  • HDU 3442 Three Kingdoms
    ProblemDescriptionThreeKingdomsisafunnygame.OftenLiuBeiisweakandhastorunaway,sointhegameLiuBeihasaskillcalled"Dunzou".Thist......
  • HDU 4127 Flood-it!
    ProblemDescriptionFlood-itisafascinatingpuzzlegameonGoogle+platform.Thegameinterfaceislikefollows:Atthebeginningofthegame,sys......
  • HDU 2757 Ocean Currents
    ProblemDescriptionForaboatonalargebodyofwater,strongcurrentscanbedangerous,butwithcarefulplanning,theycanbeharnessedtohelpthe......
  • HDU 1252 Hike on a Graph
    ProblemDescription"HikeonaGraph"isagamethatisplayedonaboardonwhichanundirectedgraphisdrawn.Thegraphiscompleteandhasallloops......
  • HDU 3345 War Chess
    ProblemDescriptionWarchessishh'sfavoritegame:Inthisgame,thereisanN*Mbattlemap,andeveryplayerhashisownMovingVal(MV).Ineach......