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
", dp[len-1]);
24     return 0;
25 }
原文地址:https://www.cnblogs.com/0xiaoyu/p/11341486.html