HDU 6122 Color the chessboard(机智)
来源:互联网 发布:网上药店软件 编辑:程序博客网 时间:2024/04/30 06:59
Description
一个
Input
第一行一整数
Output
输出方案数,结果模
Sample Input
2
2 2
RB
??
3 3
???
?R?
???
Sample Output
2
7
Solution
问题转化为对于任意一个
Code
#include<cstdio>#include<iostream>#include<cstring>#include<algorithm>#include<cmath>#include<vector>#include<queue>#include<map>#include<set>#include<ctime>using namespace std;typedef long long ll;#define maxn 1005#define mod 998244353int T,n,m,row[maxn],col[maxn],nr,nc,flag;char s[maxn];void inc(int &a,int b){ a=a+b>=mod?a+b-mod:a+b;} void dec(int &a,int b){ a=a-b<0?a-b+mod:a-b;}int mod_pow(int a,int b){ int ans=1; while(b) { if(b&1)ans=(ll)ans*a%mod; a=(ll)a*a%mod; b>>=1; } return ans;}int main(){ scanf("%d",&T); while(T--) { scanf("%d%d",&n,&m); nr=n,nc=m,flag=0; for(int i=1;i<=n;i++)row[i]=0; for(int i=1;i<=m;i++)col[i]=0; for(int i=1;i<=n;i++) { scanf("%s",s+1); for(int j=1;j<=m;j++) if(s[j]!='?'&&!(nr==-1&&nc==-1)) { int type; if(s[j]=='R')type=1; else type=2; if((i+j)&1)type=3-type; if(row[i]==3-type)nr=-1; else if(!row[i])nr--,row[i]=type; if(col[j]==3-type)nc=-1; else if(!col[j])nc--,col[j]=type; if(flag!=-1) if(flag==3-type)flag=-1; else flag=type; } } int ans=0; if(nr>=0)inc(ans,mod_pow(2,nr)); if(nc>=0)inc(ans,mod_pow(2,nc)); if(flag!=-1) { if(flag==0)dec(ans,2); else dec(ans,1); } printf("%I64d\n",ans); } return 0;}
阅读全文
0 0
- HDU 6122 Color the chessboard(机智)
- [HDU 6122] Color the chessboard
- hdu 6122 Color the chessboard
- HDU-6122 Color the chessboard(思维题)
- HDU 6122 Color the chessboard【思维】
- hdu-6122 Color the chessboard 思维
- 解题报告:HDU_6122 Color the chessboard (计数)
- hdu(1556)Color the ball
- HDU 1556 Color the ball (模拟)
- HDU 1556 Color the ball(BIT)
- Color the ball HDU
- Color the ball HDU
- Color the Ball HDU
- HDU 5301 Buildings(机智)
- HDU 6048 Puzzle(机智)
- 思维 hdu 5100 (chessboard)
- 【HDU】-5100-Chessboard(思维)
- hdu 1556 color the ball
- Linux spi 设备驱动
- 第五周 项目二 建立栈链算法库
- java web + testNG + ant + Selenium整合对IE浏览器的自动化测试一(工具安装)
- 一看就明白的爬虫入门讲解-基础理论篇(上篇)
- 从投票应用说起,功能才不是轻社交App的核心呢!
- HDU 6122 Color the chessboard(机智)
- 集合框架
- react知识点(二)
- JDK容器学习之HashMap (三) : 迭代器实现
- JAVA学习路线图
- bootstrap.js/angularJS禁用[Esc] buttion在弹窗(pupup)画面
- 再谈扁平化
- js pako.inflate 解压zlib压缩文件
- OpenStack Tacker介绍