链接
https://cn.vjudge.net/problem/URAL-1523
题意 给你一个1-n的序列 问长度为K的序列有多少种
思路 首先想到DP 递推式
dp[i][j] = ∑dp[x][j-1] ( 1<x<i,a[x] > a[i])
写成数组 即求当前(j-n)项和
#include <bits/stdc++.h>
using namespace std;
const int maxn = 20008;
const int mod = 1000000000;
int t[maxn],dp[maxn][15],a[maxn];int lb(int n)
{return n&(-n);
}
int qu(int x)
{int res = 0;while(x){res = (res+t[x])%mod;x -= lb(x);}return res;
}
void add(int x,int y,int n)
{while(x <= n){t[x] = (t[x] + y)%mod;x += lb(x);}
}
int main()
{int n,i,m,j,k;scanf("%d%d",&n,&k);for(i=1;i<=n;i++) scanf("%d",&a[i]);memset(dp,0,sizeof(dp));for(i=1;i<=n;i++){dp[i][1] = 1;}for(i=1,j=n;i<j;i++,j--) swap(a[i],a[j]);for(i=2;i<=k;i++){memset(t,0,sizeof(t));for(j=1;j<=n;j++){dp[j][i] = qu(a[j]);add(a[j],dp[j][i-1],n);}}int ans = 0;for(i=1;i<=n;i++) ans = (ans + dp[i][k]) % mod;printf("%d\n",ans);return 0;
}