zoukankan      html  css  js  c++  java
  • 【luogu4141】【bzoj2287】 消失之物 [动规 背包]

    P4141 消失之物 

    看题我直接懵逼 然后想着先打一遍统计方案的dp 猛然发现我忘了....

    灰溜溜打开学长的代码 哦!这样!其实我也可以

    我们在转移的时候 是f[v]+=f[v-a[i]] 这样统计的体积为a[i]的贡献值 所以!.....(我咕了)

    #include<iostream>
    #include<cstdio>
    #include<queue>
    #include<cstring>
    #include<cmath>
    #include<stack>
    #include<algorithm>
    using namespace std;
    #define ll long long
    #define rg register
    #define lson o<<1
    #define rson o<<1|1
    const int N=2000+5,M=200000+5,inf=0x3f3f3f3f,P=19650827;
    int n,m,a[N],f[N][N];
    template <class t>void rd(t &x){
        x=0;int w=0;char ch=0;
        while(!isdigit(ch)) w|=ch=='-',ch=getchar();
        while(isdigit(ch)) x=(x<<1)+(x<<3)+(ch^48),ch=getchar();
        x=w?-x:x;
    }
    
    int main(){
        freopen("in.txt","r",stdin);
        rd(n),rd(m);
        f[0][0]=1;
        for(int i=1;i<=n;++i){
            rd(a[i]);
            f[0][i]=1;
            for(int v=m;v>=a[i];--v)
            f[v][0]=(f[v][0]+f[v-a[i]][0])%10;
        }
        for(int i=1;i<=n;++i){
            for(int v=1;v<=m;++v)
            if(v>=a[i]) f[v][i]=(f[v][0]-f[v-a[i]][i]+10)%10;
            else f[v][i]=f[v][0];
            for(int v=1;v<=m;++v) printf("%d",f[v][i]);
            printf("
    ");
        }
        return 0;
    }
     
  • 相关阅读:
    2017-12 CDQZ集训(已完结)
    BZOJ1492 货币兑换 CDQ分治优化DP
    BZOJ2001 [Hnoi2010]City 城市建设 CDQ分治
    树套树小结
    跑路了
    NOI2020 游记
    半平面交模板
    Luogu 3245 大数
    Luogu 3246 序列
    test20190408(十二省联考)
  • 原文地址:https://www.cnblogs.com/lxyyyy/p/11172020.html
Copyright © 2011-2022 走看看