zoukankan      html  css  js  c++  java
  • 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 }
  • 相关阅读:
    redis分布式锁解决超卖问题
    redis使用
    Xcode 解决日志打印不全问题
    苹果电脑系统怎么重装?这几步就可以轻松搞定
    Mac 一键显示所有隐藏文件 不要那么六好吧
    iOS导入高德地图出现缺失armv7--"Undefined symbols for architecture armv7"
    如何生成.a文件,小心有坑!!
    保护你的代码,生成.a文件以及.framework文件需要注意的地方
    二维码扫描工具实现
    iOS 调整图片尺寸,告诉你的UI,别问我尺寸!我要最大的
  • 原文地址:https://www.cnblogs.com/0xiaoyu/p/11341486.html
Copyright © 2011-2022 走看看