|
沙发
楼主 |
发表于 2018-10-6 17:58:50
|
只看该作者
- #include<iostream>
- #include<iomanip>
- #define FOR(i,a,b) for(int i=a;i<=b;i++)
- #define ROF(i,a,b) for(int i=a;i>=b;i--)
- using namespace std;
- const int N=10005,M=2005,INF=0x7ffffff;
- int n,m,k,x[N],y[N],h[N],l[N],f[N][M],p,ans=INF;
- bool vis[N];
- int main()
- {
- cin>>n>>m>>k;
- FOR(i,1,n)cin>>x[i]>>y[i];
- FOR(i,1,k){cin>>p;cin>>l[p]>>h[p];vis[p]=1;}
- FOR(i,1,n)FOR(j,0,m+m)f[i][j]=INF;
- FOR(i,1,n)
- {
- FOR(j,x[i]+1,m+x[i])f[i][j]=min(f[i-1][j-x[i]]+1,f[i][j-x[i]]+1);
- FOR(j,m+1,m+x[i])f[i][m]=min(f[i][m],f[i][j]);
- FOR(j,1,m-y[i])f[i][j]=min(f[i][j],f[i-1][j+y[i]]);
- if(vis[i])
- {
- FOR(j,1,l[i])f[i][j]=INF;
- FOR(j,h[i],m)f[i][j]=INF;
- }
- }
- FOR(i,1,m)ans=min(f[n][i],ans);
- if(ans<INF)
- {
- cout<<1<<endl<<ans<<endl;
- return 0;
- }
- cout<<0<<endl;
- ROF(i,n,1)
- if(vis[i])
- {
- FOR(j,l[i],h[i])
- if(f[i][j]<INF)
- {
- cout<<k<<endl;
- return 0;
- }
- k--;
- }
- cout<<k<<endl;
- return 0;
- }
复制代码 |
|