D. Duff in Beach

Time Limit: 1 Sec

Memory Limit: 256 MB

题目连接

http://codeforces.com/contest/588/problem/D

Description

While Duff was resting in the beach, she accidentally found a strange array b0, b1, ..., bl - 1 consisting of l positive integers. This array was strange because it was extremely long, but there was another (maybe shorter) array, a0, ..., an - 1 that b can be build from a with formula: bi = ai mod n where a mod b denoted the remainder of dividing a by b.

Duff is so curious, she wants to know the number of subsequences of b like bi1, bi2, ..., bix (0 ≤ i1 < i2 < ... < ix < l), such that:

  • 1 ≤ x ≤ k
  • For each 1 ≤ j ≤ x - 1, 
  • For each 1 ≤ j ≤ x - 1, bij ≤ bij + 1. i.e this subsequence is non-decreasing.

Since this number can be very large, she want to know it modulo 109 + 7.

Duff is not a programmer, and Malek is unavailable at the moment. So she asked for your help. Please tell her this number.

Input

The first line of input contains three integers, n, l and k (1 ≤ n, kn × k ≤ 106 and 1 ≤ l ≤ 1018).

The second line contains n space separated integers, a0, a1, ..., an - 1 (1 ≤ ai ≤ 109 for each 0 ≤ i ≤ n - 1).

Output

Print the answer modulo 1 000 000 007 in one line.

Sample Input

3 5 3
5 9 1

Sample Output

10

HINT

题意

给你n,l,k,然后就是告诉你b有l长度,其中是由a不停重复得到的

然后问你一共有多少个满足条件的序列存在

条件如下:

1.这个序列的长度大于等于1,小于等于k

2.这个序列在每一个块中只能选择一个数,并且都必须选择在连续的块中

3.这个序列是单调不降的

题解:

dp,由于n*k<=1e6,所以我们简单的推断是dp[n][k]的,表示第i个数长度为k的序列有多少个

其实这道题和分块差不多,在块外就用dp瞎转移

块内就暴力就好了……

只要把这个数据过了就好了

3 100 3

1 1 1

注意是upper_bound这个东西

代码:

#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<map>
using namespace std;
#define maxn 1000005
#define mod 1000000007
int a[maxn];
int b[maxn];
long long l;
int k,n;
long long dp[maxn];
long long sum[maxn];
map<int,int> HH;
map<pair<int,int>,int> H;
int tot = ;
int get(int x,int y)
{
if(H[make_pair(x,y)])
return H[make_pair(x,y)];
H[make_pair(x,y)]=tot++;
return H[make_pair(x,y)];
}
int main()
{
scanf("%d%lld%d",&n,&l,&k);
for(int i=;i<=n;i++)
{
scanf("%d",&a[i]);
b[i]=a[i];
}
sort(a+,a++n);
for(int i=;i<=n;i++)
HH[a[i]] = i;
for(int i=;i<=n;i++)
dp[get(i,)]=;
for(int j=;j<=k;j++)
{
int tot = ;
for(int i=;i<=n;i++)
{
int kk = upper_bound(a+,a+n+,a[i])-(a+);
while(tot<=kk)
{
sum[j-] += dp[get(tot,j-)];
sum[j-] %= mod;
tot++;
}
dp[get(i,j)] = sum[j-];
}
}
for(int i=;i<=n;i++)
{
sum[k] += dp[get(i,k)];
sum[k] %= mod;
}
long long ans = ;
for(int i=;i<=k&&i<=l/n;i++)
{
ans += (long long)((l/n-i+)%mod)*sum[i];
ans %= mod;
}
if(l%n==)
{
cout<<ans<<endl;
return ;
}
for(int i=;i<=l%n;i++)
{
for(int j=;j<=k&&j<=(l/n+);j++)
{
ans+=dp[get(HH[b[i]],j)];
ans%=mod;
}
}
cout<<ans<<endl;
}

Codeforces Round #326 (Div. 2) D. Duff in Beach dp的更多相关文章

  1. Codeforces Round #326 (Div. 2) C. Duff and Weight Lifting 水题

    C. Duff and Weight Lifting Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest ...

  2. Codeforces Round #326 (Div. 2) B. Duff in Love 分解质因数

    B. Duff in Love Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/588/proble ...

  3. Codeforces Round #326 (Div. 2) A. Duff and Meat 水题

    A. Duff and Meat Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/588/probl ...

  4. Codeforces Round #326 (Div. 2) B Duff in Love 简单数论 姿势涨

    B. Duff in Love time limit per test 2 seconds memory limit per test 256 megabytes input standard inp ...

  5. Codeforces Round #326 (Div. 1) - C. Duff in the Army 树上倍增算法

    题意:一个n个点的数, m个人住在其中的某些点上, 每个人的标号1-m, 询问u-v 路径上标号前a个人,并输出标号,a < 10. 作法, 利用倍增, ID[j][i] 表示i到i的第2^j个 ...

  6. Codeforces Round #326 Div.1 C.Duff in the Army 树上倍增

    题意概述: 给出一棵N个结点的树,然后有M个居民分散在这棵树的结点上(允许某个结点没有居民).现在给出一些询问形如u,v,a,定义k=min(x,a),其中x表示的是u->v路径上的居民数量.将 ...

  7. Codeforces Round #367 (Div. 2) C. Hard problem(DP)

    Hard problem 题目链接: http://codeforces.com/contest/706/problem/C Description Vasiliy is fond of solvin ...

  8. Codeforces Round #326 (Div. 2) B. Pasha and Phone C. Duff and Weight Lifting

    B. Pasha and PhonePasha has recently bought a new phone jPager and started adding his friends' phone ...

  9. Codeforces Round #326 (Div. 2)-Duff and Meat

    题意: Duff每天要吃ai千克肉,这天肉的价格为pi(这天可以买好多好多肉),现在给你一个数值n为Duff吃肉的天数,求出用最少的钱满足Duff的条件. 思路: 只要判断相邻两天中,今天的总花费 = ...

随机推荐

  1. VS2010开发2dx无法解析的外部符号解决记录

    首先新建HelloWorld项目... 想使用Cocos2d扩展包需要引入相关头文件,如:#include “cocos-ext.h”...接下来我们右键工程属性->配置属性->c/c++ ...

  2. linux 下 NetBeans 字体大小设置

    在linux mint 12下安装了 NetBeans7.1.2使用之后,觉得字体不好看,字体普遍特别大,分三个方面改NetBeans的字体. 1. 代码字体大小 点击NetBeans菜单,工具--& ...

  3. SQL2012远程连接到SQL2008时的问题:已成功与服务器建立连接,但在登陆过程中发生错误。

    服务器装的是2008,我机上装的是2012,结果一远程连接马上报错而且2012直接crash了.后来找到这位兄弟的帖子,http://www.cnblogs.com/liuguozhu2015/p/3 ...

  4. Delphi word编辑

    private void but_Table_Click(object sender, EventArgs e) { object Nothing = System.Reflection.Missin ...

  5. XAMPP:访问phpmyadmin出错的解决方案

    来源:http://www.ido321.com/1246.html XAMPP(Apache+MySQL+PHP+PERL)是一个功能强大的建 XAMPP 软件站集成软件包,轻巧,用起来很方便.它提 ...

  6. Designing Evolvable Web API with ASP.NET 随便读,随便记 “The Internet,the World Wide Web,and HTTP”——HTTP

    HTTP 我们将只聚焦在于与创建 Web APIs有关的部分. HTTP 是信息系统中的一个应用层协议,是Web的支柱. 其原先由 Berners-Lee, Roy Fielding 和 Henrik ...

  7. Linux下gcc和g++编译helloworld

    linux C(hello world) 1.使用vi/vim进行编写代码并保存为hello_world.c.如下: 1 2 3 4 5 6 /* This is my first C program ...

  8. SRM 511 DIV1 500pt(DP)

    题目简述 给定n个数,两个人轮流取数,和之前两个人的取的数或起来,谁不能取数或者谁取到的数和之前的数或值为511谁输,问谁能够赢? 题解 刚开始的想法是直接搜,不过需要记录取过的值的状态,2^50显然 ...

  9. C#中Internal class与静态类说明

    C#中的internal访问修饰符表示 访问仅限于当前程序集 但是注意,internal修饰符修饰的类中,可以有public的成员变量和成员方法等 Static 关键字作为修饰符可以用于类.方法和成员 ...

  10. 转载 JQuery中attr属性和JQuery.data()学习

    转载原地址: http://www.cnblogs.com/yeminglong/p/5405745.html 用html直接data-key来存放,key必须全部小写. <div data-m ...