zoukankan      html  css  js  c++  java
  • 【动态规划】Concerts

    Concerts

    题目描述

    John enjoys listening to several bands, which we shall denote using A through Z. He wants to attend several concerts, so he sets out to learn their schedule for the upcoming season. 
    He finds that in each of the following n days (1 ≤ n ≤ 1e5), there is exactly one concert. He decides to show up at exactly k concerts (1 ≤ k ≤ 300), in a given order, and he may decide to attend more than one concert of the same band.
    However, some bands give more expensive concerts than others, so, after attending a concert given by band b, where b spans the letters A to Z, John decides to stay at home for at least hb days before attending any other concert.
    Help John figure out how many ways are there in which he can schedule his attendance, in the desired order. Since this number can be very large, the result will be given modulo 1e9 + 7.

    输入

    The first line contains k and n. The second line contains the 26 hb values, separated by spaces.
    The third line contains the sequence of k bands whose concerts John wants to attend e.g.,AFJAZ, meaning A, then F etc. The fourth line contains the schedule for the following n days,specified in an identical manner.

    输出

    The number of ways in which he can schedule his attendance (mod 1e9 + 7).

    样例输入

    2 10
    1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
    AB
    ABBBBABBBB
    

    样例输出

    10


    【题意】

    定义S串,T串。分别是输入的第一个,第二个字符串。

    给出26种音乐会,每次举行完必须要休息多少天。

    然后S串是必须按照这个顺序去看的音乐会。

    但是然后T串是。音乐会的时间安排。

    问有多少种方案满足这个自己计划。


    【题解】

    然后定义dp[i][j],对应的是,已经完成第i~k及以后的计划,在第j天的这一天 方案数

    可能比较绕。

    从后往前考虑,

    1、预处理出最后计划最后一场的位置的方案数为1。

    2、然后从后往前进行递推。

     1 #include<bits/stdc++.h>
     2 using namespace std;
     3 const int N = 1e5+10;
     4 const int M = 3e2+5;
     5 const int mod = 1e9+7;
     6 typedef long long ll;
     7 int f[N][M];
     8 int S[N],T[N];
     9 int n,k;
    10 int w[30];
    11 char str[N];
    12 int main()
    13 {
    14     scanf("%d%d",&k,&n);
    15     for(int i=0;i<26;i++)   scanf("%d",&w[i]);
    16  
    17     scanf("%s",str+1);
    18     for(int i=1;str[i];i++) S[i] = str[i] - 'A';
    19  
    20     scanf("%s",str+1);
    21     for(int i=1;str[i];i++) T[i] = str[i] - 'A';
    22  
    23     //初始化
    24     for(int i=n;i>=1;i--){
    25         f[i][k] = f[i+1][k] ;
    26         if( T[i] == S[k] )
    27             f[i][k] = f[i][k] + 1 ;
    28     }
    29  
    30     for(int i=n;i>=1;i--){
    31         for(int j=k-1;j>=1;j--){
    32             f[i][j] = f[i+1][j];
    33             if( T[i] == S[j] && i+w[T[i]]+1 <= n ){
    34                 f[i][j] = (int)((ll)f[i][j] + (ll)f[i+w[T[i]]+1][j+1] )% mod ;
    35             }
    36         }
    37     }
    38      
    39     printf("%d
    ",f[1][1]);
    40     return 0;
    41 }
    View Code
  • 相关阅读:
    就没有我遇不到的报错!java.lang.NoClassDefFoundError: org/apache/hadoop/hbase/filter/Filter
    【HBase】通过Bulkload批量加载数据到Hbase表中
    【HBase】HBase和Hue的整合
    【HBase】协处理器是什么?又能干什么?怎么用?
    【HBase】带你了解一哈HBase的各种预分区
    【HBase】快速了解上手rowKey的设计技巧
    【HBase】HBase和Sqoop整合
    【HBase】快速搞定HBase与Hive的对比、整合
    hive元数据报错?试了很多方法都没辙?也许你漏了这一步
    【HBase】HBase与MapReduce集成——从HDFS的文件读取数据到HBase
  • 原文地址:https://www.cnblogs.com/Osea/p/11387702.html
Copyright © 2011-2022 走看看