Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<cstdio>
- #include<algorithm>
- using namespace std;
- const int maxn=1e3+2;
- const int mod=998244353;
- int n,k,ans;
- int a[maxn];
- int dp[maxn][maxn];
- void DP(){
- for (int i=1;i<=a[n]/(k-1)+1;i++){
- dp[0][0]=1;
- for (int l=1,r=0;l<=n;l++){
- while (a[r+1]+i<=a[l]) r++;
- dp[l][0]=dp[l-1][0];
- for (int pos=1;pos<=l&&pos<=k;pos++) dp[l][pos]=(dp[l-1][pos]+dp[r][pos-1])%mod;
- }
- ans=(ans+dp[n][k])%mod;
- }
- }
- int main(){
- scanf("%d%d",&n,&k);
- for (int i=1;i<=n;i++) scanf("%d",&a[i]);
- sort(a+1,a+n+1);
- DP();
- printf("%d",ans);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement