首页 > 其他分享 >abc232e Rook Path

abc232e Rook Path

时间:2023-08-22 09:04:08浏览次数:61  
标签:Rook mat int ll abc232e y1 Path fo lld

开始看成走到相邻格子,后面发现是车的走法。。。

发现可以将整个图分成四个部分,
(x1,y1)
\((x,y1) (x \neq x1)\)
\((x1,y) (y\neq y1)\)
\((x,y) (x\neq x1 ,y\neq y1)\)
然后每一部分中的点的答案都是相同的,转移即可。

#include<algorithm>
#include<cstdio>
#include<cstring>
#include<map>
#define fo(i,a,b) for (int (i)=(a);(i)<=(b);(i)++)
#define fd(i,b,a) for (int (i)=(b);(i)>=(a);(i)--)
#define mk(x,y) make_pair((x),(y))
using namespace std;
typedef long long ll;
const ll mo=998244353;
const int N=1e6+5;
ll n,m,k;
int a,b,c,d;
struct mat{
    ll a[4][4];
};
mat t,y;
void add(ll &x,ll y){
    x=(x+y)%mo;
}
mat mul(mat a,mat b){
    mat c;
    fo(i,0,3) fo(j,0,3) c.a[i][j]=0;
    fo(i,0,3) fo(j,0,3) fo(k,0,3) {
        add(c.a[i][j], a.a[i][k]*b.a[k][j]%mo);
    }
    return c;
}
void power(ll b){
    while (b) {
        if (b&1) t=mul(t,y);
        y=mul(y,y);
        b/=2;
    }
}
int main() {

    // #ifdef  LOCAL
    //     freopen("in.txt","r",stdin);
    //     freopen("out.txt","w",stdout);
    // #endif

    scanf("%lld %lld %lld",&n,&m,&k);
    scanf("%d %d %d %d",&a,&b,&c,&d);

    t.a[0][0]=t.a[1][1]=t.a[2][2]=t.a[3][3]=1;

    ll z[4][4]={
        0,m-1,n-1,0,
        1,m-2,0,n-1,
        1,0,n-2,m-1,
        0,1,1,n+m-4
    };
    fo(i,0,3) fo(j,0,3) y.a[i][j]=z[i][j];

    power(k);

    if (a==c && b==d) printf("%lld",t.a[0][0]);
    if (a==c && b!=d) printf("%lld",t.a[1][0]);
    if (a!=c && b==d) printf("%lld",t.a[2][0]);
    if (a!=c && b!=d) printf("%lld",t.a[3][0]);


} 

标签:Rook,mat,int,ll,abc232e,y1,Path,fo,lld
From: https://www.cnblogs.com/ganking/p/17647550.html

相关文章

  • [转]By not providing "FindEigen3.cmake" in CMAKE_MODULE_PATH this project has
    在编译安装的时候出现如下问题,是Eigen3的Cmake依赖问题,已经安装eigen3,但在项目的find_package(Eigen3QUERIED)中,无法找到FindEigen3.Cmake. CMakeErroratloam_velodyne/CMakeLists.txt:13(find_package):Bynotproviding"FindEigen3.cmake"inCMAKE_MODULE_......
  • [SQL Server---For XML PATH 的运用]
    SELECTA.CID,B.TrueNameinto#UserNameFROMRH_CommuUserRoleAWITH(NOLOCK)LeftjoinRH_UserBWITH(NOLOCK)onA.UserID=B.idANDA.UType=1WHEREB.UserState=1selectCID,TrueName=STUFF((select','+ltrim(TrueName)from#UserNamewhereCID=t.CIDfo......
  • url函数和path函数的区别??
    在Django中,path()和url()都是用于定义URL路由的函数,但它们有一些区别:path()函数:path()函数是Django2版本中引入的新函数,用于定义URL路由。它使用简单的字符串匹配来匹配URL,不支持正则表达式。在path()中,斜杠/被用作路径分隔符,而不需要使用正则表达式中......
  • [LeetCode][62]unique-paths
    ContentThereisarobotonanmxngrid.Therobotisinitiallylocatedatthetop-leftcorner(i.e.,grid[0][0]).Therobottriestomovetothebottom-rightcorner(i.e.,grid[m-1][n-1]).Therobotcanonlymoveeitherdownorrightatanypointi......
  • [LeetCode][64]minimum-path-sum
    ContentGivenamxngridfilledwithnon-negativenumbers,findapathfromtoplefttobottomright,whichminimizesthesumofallnumbersalongitspath.Note:Youcanonlymoveeitherdownorrightatanypointintime. Example1:Input:grid=[[......
  • LeetCode[64]MinimumPathSum
    ContentGivenamxngridfilledwithnon-negativenumbers,findapathfromtoplefttobottomright,whichminimizesthesumofallnumbersalongitspath.Note:Youcanonlymoveeitherdownorrightatanypointintime. Example1:Input:grid=[[......
  • LeetCode[62]UniquePaths
    ContentThereisarobotonanmxngrid.Therobotisinitiallylocatedatthetop-leftcorner(i.e.,grid[0][0]).Therobottriestomovetothebottom-rightcorner(i.e.,grid[m-1][n-1]).Therobotcanonlymoveeitherdownorrightatanypointi......
  • Atcoder_[abc284E]Count Simple Paths题解
    题目链接这题就是很简单的图上深搜,我觉得放在E题太水了,代码里有详细注释。#include<bits/stdc++.h>usingnamespacestd;#defineintlonglongvector<int>v[200010];//邻接表intans;//答案boolvis[200010];//vis[i]记录i号点有没有被访问过voiddfs(intx)......
  • No_62_UniquePaths
    ContentThereisarobotonanmxngrid.Therobotisinitiallylocatedatthetop-leftcorner(i.e.,grid[0][0]).Therobottriestomovetothebottom-rightcorner(i.e.,grid[m-1][n-1]).Therobotcanonlymoveeitherdownorrightatanypointi......
  • Node.js:path文件路径操作模块
    path用于文件路径操作官方文档https://nodejs.org/api/path.html一个不错的解释┌─────────────────────┬────────────┐│dir│base│├──────┬├──────┬─────┤│......