Advertisement
dudu2004

1188C Array Beauty && 1189F Array Beauty

Jul 22nd, 2019
152
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.56 KB | None | 0 0
  1. #include<cstdio>
  2. #include<algorithm>
  3. using namespace std;
  4. const int maxn=1e3+2;
  5. const int mod=998244353;
  6. int n,k,ans;
  7. int a[maxn];
  8. int dp[maxn][maxn];
  9. void DP(){
  10.     for (int i=1;i<=a[n]/(k-1)+1;i++){
  11.         dp[0][0]=1;
  12.         for (int l=1,r=0;l<=n;l++){
  13.             while (a[r+1]+i<=a[l]) r++;
  14.             dp[l][0]=dp[l-1][0];
  15.             for (int pos=1;pos<=l&&pos<=k;pos++) dp[l][pos]=(dp[l-1][pos]+dp[r][pos-1])%mod;
  16.         }
  17.         ans=(ans+dp[n][k])%mod;
  18.     }
  19. }
  20. int main(){
  21.     scanf("%d%d",&n,&k);
  22.     for (int i=1;i<=n;i++) scanf("%d",&a[i]);
  23.     sort(a+1,a+n+1);
  24.     DP();
  25.     printf("%d",ans);
  26.     return 0;
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement