hdu5965扫雷
来源:互联网 发布:淘宝联盟高佣金多少 编辑:程序博客网 时间:2024/06/05 10:48
题目链接:
hdu5965
题意:
中文题
题解:
我们去枚举前两列的状态然后其他列的状态就确定下来了,因为前两列的状态最多只有三种,所以时间复杂度为O(n),然后特判一下长度为1的情况就可以了。
代码:
#include<bits/stdc++.h> using namespace std; #pragma comment(linker, "/STACK:102400000,102400000") #define ls i<<1 #define rs ls | 1 #define mid ((ll+rr)>>1) #define pii pair<int,int> #define MP make_pair typedef long long LL; const long long INF = 1e18+1LL; const double Pi = acos(-1.0); const int N = 1e4+10, maxn = 1e3+20, inf = 2e9; const LL mod = 100000000+7; int n; char a[N]; int b[N]; LL cc(int x){ if(x==0||x==2) return 1ll; return 2ll; } int main(){ int T; scanf("%d",&T); while(T--){ scanf("%s",a); n=strlen(a); for(int i=0;i<n;i++) a[i]-='0'; if(n==1){ if(a[0]==1) puts("2"); else if(a[0]==0||a[0]==2) puts("1"); else puts("0"); continue; } LL ans=0; for(int x=0;x<=min(2,(int)a[0]);x++){ ///printf("x = %d\n",x); LL sum=1; if(a[0]-x>2||a[0]-x<0) continue; b[0]=a[0]-x,b[1]=x; sum=sum*cc(b[0])%mod,sum=sum*cc(b[1])%mod; for(int i=2;i<n;i++){ b[i]=a[i-1]-b[i-1]-b[i-2]; if(b[i]<0||b[i]>2) {sum=0;break;} sum=sum*cc(b[i])%mod; } if(b[n-1]+b[n-2]!=a[n-1]) sum=0; ans=(ans+sum)%mod; ///printf("%d %d sum = %lld\n",a[0]-x,x,sum); } printf("%lld\n",ans); } return 0; }
0 0
- hdu5965扫雷
- HDU5965-扫雷
- 2016 ccpc 合肥 HDU5965 扫雷
- HDU5965 扫雷(记忆化搜索)
- HDU5965 扫雷(递推)
- HDU5965扫雷(递推)
- HDU5965 扫雷 —— dp递推
- bfs hdu5965
- hdu5965(思维)
- 扫雷
- 扫雷
- 扫雷
- 扫雷
- 扫雷
- 扫雷
- 扫雷
- 扫雷
- 扫雷
- HelloDjango
- POJ2506 Tiling(递推+大数)
- 通过自定义.xml文件实现各种效果的SeekBar
- 【Demo】UITableView实现分组可折叠下拉列表
- 动态规划专题 01背包问题详解【转】
- hdu5965扫雷
- HDU-2818-Building Block
- ViewPager组件的使用
- C语言/C++|Bubble Sort(冒泡排序)
- python一行代码解决SyntaxError: Non-ASCII character '\xe4'
- spring框架基于注解aop的通知
- PHP的错误和异常处理
- 自己写个vue.js插件(1):自定义指令的妙用
- JDBC连接数据库的代码及步骤