20130709 【南华大学 ACM】 新生赛第二场 【F. Little Sheep and a paper】


Problem F: Little Sheep and a paper

Time Limit: 2 Sec  Memory Limit:128 MB

Description

One day, Little Sheep gets an AK(all kill) in a contest, so he is very boring, then he just plays with a
paper. The paper has two faces called A and B. Sheep finds the paper can be folded for infinity times,
and now Sheep thinks the paper is interesting, so he tries to fold the paper in half for many times. He
finds out he has four way to make the paper folded in half, there are listed below:
At first, Little Sheep keeps the face A of the paper faced to him,and he fold the paper for many times.
In the end, Sheep opens up the paper, and keeps the face A faced to him again. Now the question is :
How many creases on the face A of the paper are protruding? God sheep solves the question without 2
seconds. Can you? You should make your answer mod 100000009.

Input

The first line of input contains a single positive integer N , which means the number of test cases.
The following N lines gives N non-empty strings containing only characters in ”UDLR”, which is the
sequences of the actions of the Sheep to fold paper. The length of the each string is a positive number
less than 10^6.

Output

For each case output the answer mod 100000009 in a line.

Sample Input

4
L
LR
DLUR
ULULL

Sample Output

0
1
10
22

----------------------------------------------------------------------------------------------------------

解题报告:


暂缓





----------------------------------------------------------------------------------------------------------

代码:

#include<stdio.h>
#include<string.h>

const long MOD=100000009;

long long power(long long a,long b)
{
	if( !b )		return 1;
	if( 1==b )		return a%MOD;
	long long 	x = power(a,b>>1);
	long long 	ans = x*x%MOD;
	if( b&1 )	ans = a*ans%MOD;
	return ans;
}

int main()
{
	long n,i,x,y;
	long long sumx,sumy;
	char ch[1000005];
	scanf("%ld",&n);
	while( n-- )
	{
		scanf("%s",ch);
		for(x=y=0,i=1;ch[i];i++)
		{
			if( 'D'==ch[i] || 'U'==ch[i] )	y++;
			else							x++;
		}
		sumx=power(2,x)%MOD;
		sumy=power(2,y)%MOD;
		printf("%lld\n",((sumx-1)*sumy%MOD+(sumy-1)*sumx%MOD)%MOD);
	}
	return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值