分析
这题简单的DP,关键是怎么判断轻功在这一段中可用
建一个h[i][j]表示在从起点到第i个桩子,j的功法被禁用的次数(就是前缀和)
然后减一下为0就可以转移啦
#include <iostream> #include <cstdio> #include <memory.h> using namespace std; typedef long long ll; const int N=5e2+10; const int K=1e2+10; ll w[K],a[K]; int n,k,q; ll W; ll f[N][K]; int h[N][K]; int main() { freopen("qinggong.in","r",stdin); freopen("qinggong.out","w",stdout); scanf("%d%d%lld",&n,&k,&W); for (int i=1;i<=k;i++) scanf("%lld%lld",&a[i],&w[i]); scanf("%d",&q); for (int i=1;i<=q;i++) { int a,b; scanf("%d%d",&a,&b); h[a][b]=1; } for (int i=1;i<=n;i++) for (int j=1;j<=k;j++) h[i][j]+=h[i-1][j]; for (int i=1;i<=n;i++) for (int j=1;j<=k;j++) f[i][j]=1ll<<62; for (int i=1;i<=n;i++) for (int j=1;j<=k;j++) for (int l=1;l<=k;l++) if (i-a[l]>=0&&h[i][l]-h[i-a[l]][l]==0&&f[i-a[l]][j]!=1ll<<62) f[i][l]=min(f[i][l],f[i-a[l]][j]+w[l]+(j==l?0:W)); ll ans=1ll<<62; for (int i=1;i<=k;i++) ans=min(ans,f[n][i]); printf("%lld",ans==1ll<<62?-1:ans); fclose(stdin);fclose(stdout); }