dp[i][j][0/1]一下,然后发现可以BIT搞。注意外层for所有点。
#include<iostream> #include<cstdio> #include<cstring> #include<algorithm> #define maxn 50050 #define mod 100007 using namespace std; int n,k,f[maxn][12][2],t[maxn<<1][12][2],mx=0; struct pnt { int x,y; }p[maxn]; bool cmp(pnt x,pnt y) { return x.x<y.x; } int lowbit(int x) { return (x&(-x)); } void modify(int x,int a,int b,int val) { for (int i=x;i<=mx;i+=lowbit(i)) t[i][a][b]=(t[i][a][b]+val)%mod; } int ask(int x,int a,int b) { int ret=0; for (int i=x;i>=1;i-=lowbit(i)) ret=(ret+t[i][a][b])%mod; return ret; } int main() { scanf("%d%d",&n,&k); for (int i=1;i<=n;i++) { scanf("%d%d",&p[i].x,&p[i].y); mx=max(mx,p[i].y); } sort(p+1,p+n+1,cmp); modify(p[1].y,0,0,1);modify(p[1].y,0,1,1); for (int i=2;i<=n;i++) { for (int j=1;j<=k;j++) { f[i][j][0]=ask(p[i].y-1,j-1,1)+ask(p[i].y-1,j,0);f[i][j][0]%=mod; f[i][j][1]=ask(mx,j,1)-ask(p[i].y,j,1)+ask(mx,j-1,0)-ask(p[i].y,j-1,0); f[i][j][1]%=mod;if (f[i][j][1]<0) f[i][j][1]+=mod; modify(p[i].y,j,0,f[i][j][0]);modify(p[i].y,j,1,f[i][j][1]); } modify(p[i].y,0,0,1);modify(p[i].y,0,1,1); } int ans=0; for (int i=1;i<=n;i++) ans=(ans+f[i][k][0]+f[i][k][1])%mod; printf("%d\n",ans); return 0; }