dp大水题
由于未知错误wa了一个点
乱改了一下就A了
瘫
#include<cstdio> #include<iostream> #include<cstring> #include<algorithm> #define rint register int #define INF 9999999999 using std::min; template <class T>inline void read(T &X) { X=0;int W=0;char ch=0; while(!isdigit(ch))W|=ch=='-',ch=getchar(); while(isdigit(ch))X=(X<<3)+(X<<1)+(ch^48),ch=getchar(); X=W?-X:X;return; } int n,K,W,Q,a[110],v[110],mark[510][110]={0},mk[110]={0}; long long dp[510][110],ans(INF); bool boo=false; void init() { read(n),read(K),read(W); a[0]=0,v[0]=0; for(rint i=1;i<=K;++i) { read(a[i]),read(v[i]); if(v[i]==0)boo=true; } read(Q); int x,k; for(rint i=1;i<=Q;++i) read(x),read(k),mark[x][k]=1,mk[k]=1; if(boo){printf("0 ");return;} for(rint i=1;i<=n;++i) for(rint j=0;j<=K;++j) dp[i][j]=INF; for(rint j=0;j<=K;++j)dp[0][j]=0; } int main() { // freopen("qinggong.in","r",stdin); // freopen("qinggong.out","w",stdout); init(); if(boo)return 0; for(rint i=1;i<=n;++i) { for(rint j=1;j<=K;++j) { if(a[j]>i)continue; bool boo(false); for(rint k=i-a[j];k<=i;++k) { if(!Q||!mk[j])break; if(mark[k][j]){boo=true;break;} } if(boo)continue; for(rint lastj=0;lastj<=K;++lastj) { if(i<a[j]+a[lastj])continue; bool boo1(false); for(rint k=i-a[j]-a[lastj];k<=i-a[j];++k) { if(k==0)continue; if(!Q||!mk[lastj])break; if(mark[k][lastj]){boo1=true;break;} } if(boo1)continue; dp[i][j]=min(dp[i][j],dp[i-a[j]][j]+v[j]); dp[i][j]=min(dp[i][j],dp[i-a[j]][lastj]+v[j]+W); } } } for(rint j=1;j<=K;++j) ans=min(ans,dp[n][j]); if(ans==INF)ans=-1; printf("%lld ",ans); return 0; }