bzoj 2431: [HAOI2009]逆序对数列
一个比较弱智的DP
1 #include<cstdio> 2 #include<iostream> 3 #include<cstring> 4 #include<cstdlib> 5 #include<cmath> 6 #include<queue> 7 #include<algorithm> 8 #include<vector> 9 #define M 1009 10 #define EPS 1e-10 11 #define MO 10000 12 #define ll long long 13 using namespace std; 14 ll read() 15 { 16 char ch=getchar(); 17 ll x=0,f=1; 18 for(;ch<'0'||ch>'9';ch=getchar()) 19 if(ch=='-') 20 f=-1; 21 for(;ch>='0'&&ch<='9';ch=getchar()) 22 x=x*10+ch-'0'; 23 return x*f; 24 } 25 int n,k,f[M][M],sum[M][M]; 26 int main() 27 { 28 n=read(); 29 k=read(); 30 for(int i=0;i<=n;i++) 31 f[i][0]=sum[i][0]=1; 32 for(int i=1;i<=n;i++) 33 for(int j=1;j<=min(k,(i-1)*i/2);j++) 34 { 35 if(j-i>=0) 36 f[i][j]=(sum[i-1][min(j,(i-2)*(i-1)/2)]-sum[i-1][max(0,j-i)]+MO)%MO; 37 else 38 f[i][j]=sum[i-1][min(j,(i-2)*(i-1)/2)]%MO; 39 sum[i][j]=(sum[i][j-1]+f[i][j])%MO; 40 } 41 printf("%d\n",f[n][k]); 42 return 0; 43 } 44