hdu4346 枚举思维
来源:互联网 发布:beat it 编辑:程序博客网 时间:2024/05/15 04:56
http://acm.hdu.edu.cn/showproblem.php?pid=4346
Problem Description
There is a road from city A to city B.On the road,there are N positions(indexed from 0 to N-1).In order to celebrate the Multi-University training,the mayor of city A commands a worker to insert N flags on the N positions.The color of a flag is either red or green.We call the road is beautiful if and only if there exists at least one pair of non-negative integers (a,b) (0<=a<b<N and (a+b) is an even number) such that both a-th flag and b-th flag are red and (a+b)/2-th flag is green.Otherwise we call the road is ugly.Now,some positions have already been inserted flags.In order to make the road beautiful,the worker must carefully insert the flags on the positions which haven't been inserted.He wants to know how many different types of beautiful road he can make.The type of the road only depends on the flags' color.
Input
The first line of the input is the number of cases. On each case there is a line consists of a string.The length of the string is N.(0<=N<=800).The i-th character of the string is 'R' or 'G' or '?'.'R' means the flag on the i-th position which has been inserted is red.'G' means the flag on the i-th position which has been inserted is green.'?' means the i-th position hasn't been inserted a flag.
Output
A single line with the number of different types of road the worker can make,modulo 1,000,000,007.
Sample Input
4?GRG????????
Sample Output
0114
/**http://blog.csdn.net/julyana_lin/article/details/7849006*/#include <stdio.h>#include <string.h>#include <algorithm>#include <iostream>using namespace std;typedef long long LL;const int mod=1000000007;LL mod_pow(int a,int n,int p){ LL ret=1; LL A=a; while(n) { if(n&1) { ret=(ret*A)%p; } A=(A*A)%p; n>>=1; } return ret;}int main(){ int T; scanf("%d",&T); while(T--) { char a[1005]; scanf("%s",a); int n=strlen(a); int unknown=0,r_num=0; for(int i=0;i<n;i++) { if(a[i]=='?') unknown++; else if(a[i]=='R') r_num++; } LL unbea=(r_num==0); for(int i=0;i<n;i++) { if(a[i]=='R'||a[i]=='?') { int x=(a[i]=='R'); unbea=(unbea+(x==r_num))%mod; for(int len=1;len+i<n;len+=2) { int y=x; for(int j=i+len;j<n;j+=len) { y+=(a[j]=='R'); if(a[j]=='G')break; unbea=(unbea+(y==r_num))%mod; } } } } printf("%I64d\n",mod_pow(2,unknown,mod)-unbea); } return 0;}
0 0
- hdu4346 枚举思维
- HDU5936折半枚举+思维
- !hdu 4091--贪心、枚举--(思维)
- 【思维+枚举】wust1266 gcd和lcm
- hdu 5908 Abelian Period【思维+暴力枚举】
- Codeforces 551B ZgukistringZ【思维+枚举】
- Hrbust 1789 通信道路【思维+暴力枚举】
- SCU4439 二分+枚举进制+思维
- FZU 2252 Yu-Gi-Oh!【思维+枚举】
- 玲珑杯 A 枚举 思维 数学
- hdu2197 本原串 枚举因子 思维
- HDU --- 5778 abs 【枚举平方数 + 思维】
- hihocoder 1326 dp OR 思维+枚举
- hdu 5695 扫雷(思维)(遇事不决就枚举)
- hdu 5812 Distance 数论+思维枚举
- Hdu 5936 Difference【思维+折半枚举+二分】
- FZU 2252 Yu-Gi-Oh! 思维 枚举
- CF 475D CGCDSSQ 枚举,思维+gcd
- Unity之一天一个技术点(八)---旋转问题
- Unity之一天一个技术点(九)---EasyTouch 旋转镜头
- spring mvc+ibatis+mysql的组合框架入门实例demo源码下载
- 查看ADT版本,安装、卸载、更新eclipse中的ADT
- oracle v$sqlarea 分析SQL语句使用资源情况
- hdu4346 枚举思维
- 如何在T-sql 中实现数组的功能
- 《信息系统项目管理师教程》读书笔记—第一章 绪论
- 关于IOS的蓝牙
- JFinal框架的使用(一)
- android setOnClickListener 回调函数理解
- 计算下10000! 的阶乘的结果是多少位?
- Android studio 启动时出现Android studio was unable to create a local connection in order
- PHP扩展开发探索(一)