Weather Station(基础DP)2016-2017 ACM Central Region of Russia Quarterfinal Programming Contest

Albert is a well-known inventor. He’s the one who designed an electronic weather station that periodically track all kinds of weather parameters and records the results of its measurements. While scanning the records made by the weather station, Albert discovered one important omission: wind direction data were recorded in one line without any separator characters. Albert became curious how many different solutions there would be if he tried to restore the original sequence of measurements. The inventor wanted you to know that the station distinguishes eight different wind directions and encodes each one of them with one or two characters. In addition, he has drawn a picture with wind direction notations used by the weather station. Your task is to write a program that will calculate the number of original sequences for a specific record based on weather station data. Albert realizes that the resulting number may be quite large, so your task is merely to calculate the value modulo 109 + 7.

Limitations

The length of the input line does not exceed 105 .

Input

The input file consists of a single line that contains a record made by the weather station. The record is a line of wind direction values containing characters N, S, W, and E.

Output

Output file must contain integer number of possible solutions modulo 109 + 7.

Examples

Input.txt

NEWS

EWNS

Output.txt

2

1

Note

The line in the first example has two solutions: {N, E, W, S} and {NE, W, S}.

The line in the second example has one solution: {E, W, N, S}.

 

 1 #include <stdio.h>
 2 #include <string.h>
 3 
 4 #define mod 1000000007
 5 
 6 int main()
 7 {
 8     freopen("input.txt", "r", stdin);
 9     freopen("output.txt", "w", stdout);
10     long long len, i, dp[100005];
11     char a[100005];
12     scanf("%s", a);
13     len = strlen(a);
14     dp[0] = 1;
15     i = 1;
16     if((a[i]=='W'||a[i]=='E')&&(a[i-1]=='N'||a[i-1]=='S')) dp[1] = 2;
17     else dp[1] = 1;
18     for(i=2;i<len;i++)
19     {
20         if((a[i]=='W'||a[i]=='E')&&(a[i-1]=='N'||a[i-1]=='S')) dp[i] = (dp[i-1] + dp[i-2])%mod;
21         else dp[i] = dp[i-1]%mod;
22     }
23     printf("%lld\n", dp[len-1]);
24     return 0;
25 }

 

转载于:https://www.cnblogs.com/0xiaoyu/p/11341486.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值