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 }
  • 相关阅读:
    自己动手丰衣足食之轮播图一动态修改marginTop属性实现轮播图
    自己动手丰衣足食之 jQuery 数量加减插件
    Asp.net 中,在服务端向客户端写脚本的常用方法
    Asp.Net使用加密cookie代替session验证用户登录状态 源码分享
    Javascript技术之详尽解析event对象
    Javascript的V8引擎研究
    11个实用的CSS学习工具[转载收藏]
    为什么JavaScript声明变量的时候鼓励加var关键字
    asp.net菜鸟到中级程序员的飞跃 --30本好书点评
    创建安全的ashx文件,ashx编译
  • 原文地址:https://www.cnblogs.com/0xiaoyu/p/11341486.html
Copyright © 2011-2022 走看看