codeforces587B Duff in Beach

题意就是两个数组A,B其中B[i] = A[i%n],B有l个元素,A有n个元素。

从B中选取x个元素,相邻元素在B中的下标满足Ij/n + 1 == I[j+1]/n。

可以用dp[i][j]表示第i个数选的是j,那么dp[i][j] = ∑dp[i-1][t] && t <= j。

数字比较大,得先离散化一下,且要用滚动数组。。。。

/*****************************************
Author      :Crazy_AC(JamesQi)
Time        :2016
File Name   :
*****************************************/
// #pragma comment(linker, "/STACK:1024000000,1024000000")
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <sstream>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <vector>
#include <map>
#include <set>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <climits>
using namespace std;
#define MEM(x,y) memset(x, y,sizeof x)
#define pk push_back
typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int,int> ii;
typedef pair<ii,int> iii;
const double eps = 1e-10;
const int inf = 1 << 30;
const int INF = 0x3f3f3f3f;
const int MOD = 1e9 + 7;
LL dp[2][1000010];
LL a[1000010],b[1000010];
int n, k;
LL l;
int main()
{    
    // freopen("in.txt","r",stdin);
    // freopen("out.txt","w",stdout);
    cin >> n >> l >> k;
    for (int i = 1;i <= n;++i) {
        // cin >> a[i];
        scanf("%I64d",&a[i]);
        b[i] = a[i];
    }
    sort(b + 1,b + 1 + n);
    int cnt = unique(b + 1,b + 1 + n) - b;
    for (int i = 1;i <= n;++i) {
        a[i] = lower_bound(b + 1,b + cnt, a[i]) - b;
        // cout << a[i] << ' ';
    }
    // cout << endl;
    int now = 1, la = 0;
    dp[now][0] = 1;
    LL ans = 0;
    LL seg = l / n;
    for (int i = 1;i <= k && i <= seg + 1;++i) {
        swap(la, now);
        for (int j = 0;j <= cnt;++j)
            dp[now][j] = 0;
        for (int j = 1;j <= cnt;++j)
            dp[la][j] = (dp[la][j-1] + dp[la][j]) % MOD;
        for (int j = 1;j <= n;++j)
            dp[now][a[j]] = (dp[now][a[j]] + dp[la][a[j]]) % MOD;
        for (int j = 1;j <= cnt;++j)
            ans = (ans + (seg - i + 1)%MOD * dp[now][j]%MOD) % MOD;
        for (int j = 1;j <= l - seg*n;++j)
            ans = (ans + dp[la][a[j]]) % MOD;
    }
    cout << ans << endl;
    return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值