首页 > 其他分享 >C. How Does the Rook Move?

C. How Does the Rook Move?

时间:2024-04-22 11:45:24浏览次数:17  
标签:cnt Rook ll 矩阵 How Does 放置 ans 第一列

原题链接

题解

1.没有棋下也算一种情况!!!!!!!!!
2.前k次放置,如果放在对角线上,会把原先n阶矩阵分解成n-1阶矩阵,如果没放在对角线上,会分割成n-2阶矩阵
3.不管如何放置,到最后第一列总有且仅有一颗棋子,第一列的第一行只能放白棋,第2到第n行可以放白棋或黑棋,所以第一列的放置有 \(2n-1\) 种情况

code

#include<bits/stdc++.h>
#define ll long long
const ll mod=1e9+7;
using namespace std;
ll t2[300005]={0};
ll ans[300005]={0};
int main()
{
    ans[0]=1;
    for(ll i=1;i<=300002;i++)
    {
        t2[i]=i*2LL;
        t2[i]%=mod;
    }
    ans[1]=1;
    ans[2]=3;
    for(ll i=3;i<=300002;i++)
    {
        ans[i]+=ans[i-1];
        ans[i]%=mod;
        ans[i]+=ans[i-2]%mod*t2[i-1]%mod;
        ans[i]%=mod;
    }


    ll t;
    cin>>t;
    while(t--)
    {
        ll n,k;
        cin>>n>>k;
        ll cnt=0;
        for(ll i=1;i<=k;i++)
        {
            ll x,y;
            cin>>x>>y;
            if(x!=y) cnt+=2;
            else cnt++;
        }
        cout<<ans[n-cnt]%mod<<endl;
    }
    return 0;
}

标签:cnt,Rook,ll,矩阵,How,Does,放置,ans,第一列
From: https://www.cnblogs.com/pure4knowledge/p/18150331

相关文章

  • CF1097F Alex and a TV Show 题解
    题目链接点击打开链接题目解法很牛的套路啊!看到集合并,且只要求奇偶性的问题,第一个想到\(bitset\)\(1,2,4\)操作都是好维护的,关键是第\(3\)个操作看到$\gcd$,首先想到莫反令\(c_{x,i}\)为集合\(x\)中数\(i\)的出现次数则\(c_{x,i}=\sum\limits_{i|j}\sum\limit......
  • cv2.imshow显示图片不全
    我们在屏幕上显示图片会用这个命令:cv2.imshow('img',pic),假如图片分辨率比较大,那么会出现显示不全的情况,例如:解决办法:在cv2.imshow前面加上cv2.namedWindow代码注意:两行代码中的窗口名必须保持一致不然无效,我这里都是'img'cv2.namedWindow('img',cv2.WINDOW_NORMAL)......
  • wpf datagrid,menuitem, style, export ,show in a another window,mvvm
    //xaml<Windowx:Class="WpfApp58.MainWindow"xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"xmlns:d="http://schemas.mic......
  • [NeuralPS2023]How Re-sampling Helps for Long-Tail Learning
    这篇文章作者写得非常详细,读起来非常舒适。Contribution:在long-taileddata中,re-sampling不一定有效。re-sampling的失败可能是对于不相关的context过拟合导致的,作者设计了实验论证了这一假说。在single-stage的框架下,作者提出了上下文转换增强(contextualtransformationau......
  • CTFshow-Web入门模块-爆破
    CTFshow-Web入门模块-爆破by故人叹、web21考察点:burpsuite使用、自定义迭代器使用题目提供了字典,要求登录并提示了爆破,使用burpsuite抓包并操作:(1)用户名一般为admin,密码随意输,抓包并发送给爆破模块。可以看到Basic后有一段base64编码,解码得到用户名:密码的格式,证明我们之......
  • CTFshow-Web入门模块-信息搜集writeip
    CTFshow-Web入门模块-信息搜集writeipby故人叹、信息搜集web1考察点:查看源码题目提示:”开发注释未及时删除“,页面源代码中可能有东西,查看页面源代码发现flag。总结查看源码的几种方式:F12打开源代码快捷键Ctrl+u在url前面加上view-source:浏览器右上角选项中的Web开......
  • CTFshow Reverse 逆向4 学习记录
     题目 分析过程 是一个无壳,64位的文件丢到IDA里面,找到main函数1int__cdecl__noreturnmain(intargc,constchar**argv,constchar**envp)2{3__int64v3;//rdx4char*v4;//[rsp+20h][rbp-18h]56qword_140004618=(__int64)malloc(1......
  • 52 Things: Number 33: How does the Bellcore attack work against RSA with CRT?
    52Things:Number33:HowdoestheBellcoreattackworkagainstRSAwithCRT?52件事:第33件:Bellcore攻击如何使用CRT对抗RSA? Thisisthelatestinaseriesofblogpoststoaddressthelistof'52ThingsEveryPhDStudentShouldKnowToDoCryptography':......
  • mysql修改密码报错:Your password does not satisfy the current policy requirements
    参考https://blog.csdn.net/u013449046/article/details/106455041这是mysql初始化时,使用临时密码,修改自定义密码时,由于自定义密码比较简单,就出现了不符合密码策略的问题。密码策略问题异常信息:ERROR1819(HY000):Yourpassworddoesnotsatisfythecurrentpolicyrequ......
  • 52 Things: Number 21: How does the CRT method improve performance of RSA?
    52Things:Number21:HowdoestheCRTmethodimproveperformanceofRSA?52件事:第21件:CRT方法如何提高RSA的性能? Thisisthelatestinaseriesofblogpoststoaddressthelistof '52ThingsEveryPhDStudentShouldKnow' todoCryptography:asetofqu......