C. Curious Array
高阶差分 自己如果举个例子会更好理解
https://www.cnblogs.com/ChopsticksAN/p/4908377.html
推式子:https://www.luogu.org/blog/MILLOPE/solution-cf407c
ps:预处理范围不要弄错
#include<bits/stdc++.h>
using namespace std;
const int mod=1e9+7;
const int maxn=100005;
int n,m;
int a[maxn],sum[110][maxn];
int qpow(int x,int p){if(p==0)return 1;int hf=qpow(x,p>>1);if(p&1)return 1ll*hf*hf%mod*x%mod;else return 1ll*hf*hf%mod;}
int inv(int x){return qpow(x,mod-2);}
int jc[2*maxn],ijc[2*maxn];
void prepare()
{
jc[0]=1;for(int i=1;i<=2e5;i++)jc[i]=1ll*jc[i-1]*i%mod;
ijc[(int)2e5]=inv(jc[(int)2e5]);for(int i=2e5-1;i>=0;i--)ijc[i]=1ll*(i+1)*ijc[i+1]%mod;
}
int C(int n,int k){if(n==0)return 1;return 1ll*jc[n]*ijc[k]%mod*ijc[n-k]%mod;}
void mp(int &x){while(x<0)x+=mod;}
int main()
{
ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
cin>>n>>m;
prepare();
for(int i=1;i<=n;i++)cin>>a[i];
for(int i=1;i<=m;i++)
{
int l,r,k;cin>>l>>r>>k;
sum[k+1][l]+=1;sum[k+1][l]%=mod;
for(int j=k+1;j>=1;j--){sum[j][r+1]-=C(k+r-l-(j-1),r-l);mp(sum[j][r+1]);sum[j][r+1]%=mod;}
}
for(int j=100;j>=0;j--)
{
int ts=0;
for(int i=1;i<=n;i++)
{
ts+=sum[j+1][i];mp(ts);ts%=mod;
sum[j][i]+=ts;sum[j][i]%=mod;
}
}
for(int i=1;i<=n;i++)
cout<<(a[i]+sum[0][i])%mod<<' ';
return 0;
}
------------------------------------------------------------------------------------------------------------------------------------------------------------------------
D. Largest Submatrix 3
dp做法:https://www.cnblogs.com/wuyuanyuan/p/8640841.html
#include<bits/stdc++.h>
using namespace std;
const int maxn=405,maxr=maxn*maxn;
int ans=1;
int n,m;
int a[maxn][maxn];
int f[maxn][maxn],p[maxn][maxr];
//fi,l,r 表示下边界是 i, 左右边界是 l,r 时,上边界的值 (取不到 )
void solve()
{
for(int i=1;i<=n;i++)
{
for(int len=1;len<=m;len++)
{
for(int l=1,r=len;r<=m;l++,r++)//确保dp顺序
{
if(l==r)f[l][r]=max(f[l][r],p[l][a[i][l]]);
else
{
f[l][r]=max(f[l][r],max(f[l][r-1],f[l+1][r]));
f[l][r]=max(f[l][r],max(p[l][a[i][r]],p[r][a[i][l]]));
if(a[i][l]==a[i][r])f[l][r]=i;
}
ans=max(ans,(i-f[l][r])*(r-l+1));
}
}
for(int j=1;j<=m;j++)p[j][a[i][j]]=i;
}
cout<<ans;
}
int main()
{
ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
cin>>n>>m;
for(int i=1;i<=n;i++)
for(int j=1;j<=m;j++)
{cin>>a[i][j];}
solve();
return 0;
}