168 条题解

  • 0
    @ 2016-07-26 21:15:34

    Free Pascal Compiler version 3.0.0 [2015/11/16] for i386
    Copyright (c) 1993-2015 by Florian Klaempfl and others
    Target OS: Win32 for i386
    Compiling foo.pas
    foo.pas(2,14) Note: Local variable "j" not used
    Linking foo.exe
    21 lines compiled, 0.0 sec, 27920 bytes code, 1268 bytes data
    1 note(s) issued
    测试数据 #0: Accepted, time = 0 ms, mem = 800 KiB, score = 10
    测试数据 #1: Accepted, time = 0 ms, mem = 800 KiB, score = 10
    测试数据 #2: Accepted, time = 0 ms, mem = 800 KiB, score = 10
    测试数据 #3: Accepted, time = 0 ms, mem = 800 KiB, score = 10
    测试数据 #4: Accepted, time = 0 ms, mem = 804 KiB, score = 10
    测试数据 #5: Accepted, time = 15 ms, mem = 800 KiB, score = 10
    测试数据 #6: Accepted, time = 15 ms, mem = 800 KiB, score = 10
    测试数据 #7: Accepted, time = 0 ms, mem = 804 KiB, score = 10
    测试数据 #8: Accepted, time = 0 ms, mem = 800 KiB, score = 10
    测试数据 #9: Accepted, time = 15 ms, mem = 800 KiB, score = 10
    Accepted, time = 45 ms, mem = 804 KiB, score = 100
    代码
    var
    vmax,mmax,i,j,n:integer;
    v,m,k:array[1..50] of integer;
    function max(x,y:integer):integer;
    begin
    if x>y then max:=x
    else max:=y;
    end;
    function dp(i,vleft,mleft:integer):integer;
    begin
    if i>n then dp:=0
    else
    if (((vleft-v[i])>=0) and ((mleft-m[i])>=0) )then
    dp:=max(dp(i+1,vleft-v[i],mleft-m[i])+k[i],dp(i+1,vleft,mleft))
    else dp:=dp(i+1,vleft,mleft);
    end;
    begin
    readln(vmax,mmax);
    readln(n);
    for i:=1 to n do read(v[i],m[i],k[i]);
    writeln(dp(1,vmax,mmax));
    end.
    感觉数据好水,递归居然也可以过0 0

  • 0
    @ 2016-07-23 14:37:40
    • 好久没爽爽地一次AC了
    • 01背包就是爽
    • 前面记忆化搜索的够了
    program NASA;
    var n,V,M,i,j,k:longint;
    a,b,c:array[1..50]of longint;
    f:array[1..10000,1..10000]of longint;
    
    function max(a,b:longint):longint;
    begin
      if a>=b then exit(a) else exit(b);
    end;
    
    begin
      readln(V,M);
      readln(n);
      for i:=1 to n do read(a[i],b[i],c[i]);
      fillchar(f,sizeof(f),0);
      for i:=1 to n do
        for j:=V downto a[i] do
          for k:=M downto b[i] do
            f[j,k]:=max(f[j,k],f[j-a[i],k-b[i]]+c[i]);
      writeln(f[V,M]);
    end.
    
    
  • 0
    @ 2016-05-23 23:29:53

    #include <cstdio>
    #include <iostream>

    int main(void){
    freopen("in.txt","r",stdin);
    int maxv,maxm,n;
    int m[60],v[60],e[60];
    int f[500][500]={0};
    scanf("%d%d%d",&maxv,&maxm,&n);
    for(int i=1;i<=n;i++)
    scanf("%d%d%d",&v[i],&m[i],&e[i]);

    for(int i=1;i<=n;i++)
    for(int j=maxv;j>=v[i];j--)
    for(int k=maxm;k>=m[i];k--)
    f[j][k]=std::max(f[j][k],f[j-v[i]][k-m[i]]+e[i]);
    printf("%d",f[maxv][maxm]);
    return 0;
    }

  • 0
    @ 2016-04-16 23:46:24

    一开始数组开小了,**我的锅!**
    测试数据 #0: Accepted, time = 140 ms, mem = 255072 KiB, score = 10
    测试数据 #1: Accepted, time = 203 ms, mem = 255072 KiB, score = 10
    测试数据 #2: Accepted, time = 203 ms, mem = 255076 KiB, score = 10
    测试数据 #3: Accepted, time = 203 ms, mem = 255072 KiB, score = 10
    测试数据 #4: Accepted, time = 203 ms, mem = 255072 KiB, score = 10
    测试数据 #5: Accepted, time = 203 ms, mem = 255072 KiB, score = 10
    测试数据 #6: Accepted, time = 187 ms, mem = 255072 KiB, score = 10
    测试数据 #7: Accepted, time = 218 ms, mem = 255072 KiB, score = 10
    测试数据 #8: Accepted, time = 203 ms, mem = 255076 KiB, score = 10
    测试数据 #9: Accepted, time = 218 ms, mem = 255076 KiB, score = 10
    Accepted, time = 1981 ms, mem = 255076 KiB, score = 100
    ---------------------------晒一个简单易懂的程序---------------------------
    ```pascal
    type int=longint;
    var
    v,m,t,i:int;
    a,b,d:array[0..401]of int;
    c:array[0..401,0..401,0..401]of int;
    function max(x,y:int):int;
    begin
    if x>y then exit(x) else exit(y);
    end;

    function f(x,y,z:int):int;
    begin
    if c[x,y,z]>0 then exit(c[x,y,z]);
    if x=0 then exit(0);
    if (a[x]>y)or(b[x]>z) then exit(f(x-1,y,z));
    f:=max(f(x-1,y-a[x],z-b[x])+d[x],f(x-1,y,z));
    c[x,y,z]:=f;
    end;

    begin
    readln(v,m);
    readln(t);
    for i:=1 to t do readln(a[i],b[i],d[i]);
    fillchar(c,sizeof(c),0);
    writeln(f(t,v,m));
    end.
    ```
    * 我在秋名山等你!!! *

  • 0
    @ 2016-02-17 18:58:01

    简单的记忆化搜索
    c++
    #include<stdio.h>
    #include<string.h>
    int f[51][401][401],V,W;
    int v[51],w[51],k[51],n;
    inline void max(int& a,int b){if(a<b)a=b;}
    int dp(int i,int j,int n){
    if(i&&j&&n>=0){
    if(~f[n][i][j]) return f[n][i][j];
    f[n][i][j]=dp(i,j,n-1);
    if(i>=v[n]&&j>=w[n])
    max(f[n][i][j],dp(i-v[n],j-w[n],n-1)+k[n]);
    return f[n][i][j];
    }
    return 0;
    }
    int main(){
    memset(f,-1,sizeof f);
    scanf("%d%d",&V,&W);
    scanf("%d",&n);
    for(int i=0;i<n;++i)
    scanf("%d%d%d",v+i,w+i,k+i);
    printf("%d",dp(V,W,n));
    }

  • 0
    @ 2016-01-26 15:34:03

    program kkk;
    var
    i,j,z,vv,mm,n,ii,jj:longint;
    l:array[0..10000,0..10000] of longint;
    v,m,ka:array[0..100000] of longint;
    function maxx(a,b:longint):longint;
    begin
    if a>b then maxx:=a
    else maxx:=b;
    end;
    begin
    readln(vv,mm);
    readln(n);
    for i:=1 to n do
    readln(v[i],m[i],ka[i]);
    for i:=1 to n do
    begin
    for z:=mm downto m[i] do
    for j:=vv downto v[i] do
    begin
    l[j,z]:=maxx(l[j,z],l[j-v[i],z-m[i]]+ka[i]);
    end;
    end;
    write(l[vv,mm]);
    end.

  • 0
    @ 2015-12-15 18:58:39

    #include <iostream>
    #include <math.h>
    #include <stdlib.h>
    #include <stdio.h>
    #include <algorithm>
    #include <string.h>
    using namespace std;
    const int N = 405;
    int maxv,maxw,n,v[N],w[N],ka[N],f[N][N];
    int main(){
    scanf("%d%d%d",&maxv,&maxw,&n);
    for(int i = 1;i <= n;i ++){
    scanf("%d%d%d",&v[i],&w[i],&ka[i]);
    }
    for(int i = 1;i <= n;i ++){
    for(int j = maxv;j >= 0;j --){
    for(int k = maxw;k >= 0;k --){
    f[j][k] = w[i] <= k &&v[i] <= j ? max(f[j - v[i]][k - w[i]]+ ka[i],f[j][k]) : f[j][k];
    }
    }
    }
    printf("%d",f[maxv][maxw]);
    return 0;
    }

  • 0
    @ 2015-10-22 15:23:30

    #include <cstdio>
    #include <cstring>

    using namespace std;

    inline int max(int a,int b) {
    return a>b?a:b;
    }

    int main(void) {
    int n=0,v1=0,v2=0;
    scanf("%d %d %d",&v1,&v2,&n);
    int w[n],c1[n],c2[n];
    for (int i=0;i<n;++i)
    scanf("%d %d %d",c1+i,c2+i,w+i);
    int f[v1+1][v2+1];
    memset(f,0,(v1+1)*(v2+1)*sizeof(int));
    for (int i=0;i<n;++i)
    for (int j=v1;j>=0;--j)
    for (int k=v2;k>=0;--k)
    if (j>=c1[i] && k>=c2[i])
    f[j][k]=max(f[j][k],f[j-c1[i]][k-c2[i]]+w[i]);
    int ans=0;
    for (int i=0;i<v1+1;++i)
    for (int j=0;j<v2+1;++j)
    if (f[i][j]>ans)
    ans=f[i][j];
    printf("%d\n",ans);
    return 0;
    }

    QwQ我好菜

  • 0
    @ 2015-10-21 19:19:11

    #include<cstdio>
    #include<iostream>
    #include<cmath>
    #include<cstring>
    #include<algorithm>
    #include<cstdlib>
    using namespace std;
    int i,j,z,n,f[401][401],w[100],c[100],v[100],W,V,t1,t2;
    int main()
    {
    memset(f,0,sizeof(f));
    //freopen("xx.in","r",stdin);
    //freopen("xx.out","w",stdout);
    cin>>V>>W>>n;
    for(i=1;i<=n;++i)
    cin>>v[i]>>w[i]>>c[i];
    for(i=1;i<=n;++i)
    for(j=V;j>=v[i];--j)
    for(z=W;z>=w[i];--z)
    f[j][z]=max(f[j][z],f[j-v[i]][z-w[i]]+c[i]);
    cout<<f[V][W];
    }

  • 0
    @ 2015-10-11 20:07:22

    在经过暴风雨之后,在经过枪林弹雨之后,AC了!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!111!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!111!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!111!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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of longint;
    v,n,m,i,j,k:longint;
    begin
    readln(v,m);
    readln(n);
    for i:=1 to n do
    readln(a[i],b[i],s[i]);
    for i:=1 to n do
    for j:=v downto a[i] do
    for k:=m downto b[i] do
    if f[j-a[i],k-b[i]]+s[i]>f[j,k] then f[j,k]:=f[j-a[i],k-b[i]]+s[i];
    writeln(f[v,m]);
    end.

    嘻嘻,好有成就感!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

  • 0
    @ 2015-08-21 19:00:47

    记录信息
    评测状态 Accepted
    题目 P1334 NASA的食物计划
    递交时间 2015-08-21 19:00:10
    代码语言 C++
    评测机 Jtwd2
    消耗时间 45 ms
    消耗内存 1136 KiB
    评测时间 2015-08-21 19:00:11
    评测结果
    编译成功

    测试数据 #0: Accepted, time = 0 ms, mem = 1128 KiB, score = 10
    测试数据 #1: Accepted, time = 15 ms, mem = 1132 KiB, score = 10
    测试数据 #2: Accepted, time = 0 ms, mem = 1136 KiB, score = 10
    测试数据 #3: Accepted, time = 15 ms, mem = 1136 KiB, score = 10
    测试数据 #4: Accepted, time = 0 ms, mem = 1132 KiB, score = 10
    测试数据 #5: Accepted, time = 15 ms, mem = 1136 KiB, score = 10
    测试数据 #6: Accepted, time = 0 ms, mem = 1132 KiB, score = 10
    测试数据 #7: Accepted, time = 0 ms, mem = 1136 KiB, score = 10
    测试数据 #8: Accepted, time = 0 ms, mem = 1136 KiB, score = 10
    测试数据 #9: Accepted, time = 0 ms, mem = 1136 KiB, score = 10
    Accepted, time = 45 ms, mem = 1136 KiB, score = 100
    代码
    #include <iostream>
    #include <stdio.h>
    using namespace std;
    int f[410][410];
    int wei[51];
    int big[51];
    int krl[51];
    int main()
    {
    int n;
    int r,p;
    scanf("%d%d",&r,&p);
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
    scanf("%d%d%d",&big[i],&wei[i],&krl[i]);

    for(int i=1;i<=n;i++)
    for(int j=r;j>=big[i];j--)
    for(int k=p;k>=wei[i];k--)
    {
    f[j][k]=max(f[j-big[i]][k-wei[i]]+krl[i],f[j][k]);
    }
    int maxans=-1000000000;
    for(int j=r;j;j--)
    for(int k=p;k;k--)
    {
    maxans=max(maxans,f[j][k]);
    }
    printf("%d",maxans);
    }

  • 0
    @ 2015-02-03 14:50:39

    #include <iostream>
    #include <algorithm>
    #include <stdio.h>
    #include <string.h>
    #include <math.h>
    #include <cstdlib>
    using namespace std;
    const int MAXN=51,MAXV=401,MAXL=401;
    int f[MAXN][MAXV][MAXL],a[MAXN],b[MAXN],c[MAXN];
    int main(){
    int i,j,k,n,m,v,g;
    cin>>v>>g;
    cin>>n;
    for(i=1;i<=n;i++) cin>>a[i]>>b[i]>>c[i];
    for(i=1;i<=n;i++) f[i][0][0]=0;
    for(j=0;j<=v;j++) f[0][j][0]=0;
    for(k=0;k<=g;k++) f[0][0][k]=0;
    for(i=1;i<=n;i++)
    for(j=0;j<=v;j++)
    for(k=0;k<=g;k++){
    f[i][j][k]=f[i-1][j][k];
    if(j>=a[i] && k>=b[i]){
    f[i][j][k]=max(f[i-1][j][k],f[i-1][j-a[i]][k-b[i]]+c[i]);
    }
    }
    cout<<f[n][v][g]<<endl;
    system("pause");
    return 0;
    }

  • 0
    @ 2015-01-22 16:27:29

    #include <iostream>
    #include <algorithm>
    #define MAXL 401
    using namespace std;

    int dp[MAXL][MAXL], W, V, n, w, v, p;

    void ZeroOnePack(int v, int w, int p);

    int main()
    {
    cin >> V >> W;
    cin >> n;
    for (int i = 1; i <= n; i++)
    {
    cin >> v >> w >> p;
    ZeroOnePack(v, w, p);
    }
    cout << dp[V][W] << endl;
    return 0;
    }

    void ZeroOnePack(int v, int w, int p)
    {
    for (int i = V; i >= v; i--)
    for (int j = W; j >= w; j--)
    dp[i][j] = max(dp[i - v][j - w] + p, dp[i][j]);
    }
    N个地方把v和w整反了,错了N次。。。

  • 0
    @ 2015-01-15 17:50:11

    感觉动态规划就是枚举嘛,诶,就是把所有状态枚举一遍,比纯枚举排除了很多情况罢了- -所以二维费用比一维费用差别就在于枚举的东西更多了而已。。吧。。

    ###blcok code
    program P1334;
    uses math;
    var data:array[0..400,0..400] of longint;
    i,v,a,b,n,maxa,maxb,j,k:longint;
    begin
    fillchar(data,sizeof(data),0); read(maxa,maxb);
    read(n);
    for i:=1 to n do
    begin
    read(a,b,v);
    for j:=maxa downto a do
    for k:=maxb downto b do
    data[j,k]:=max(data[j,k],data[j-a,k-b]+v);
    end;

    write(data[maxa,maxb]);
    end.

  • 0
    @ 2014-10-26 10:54:00

    #include<cmath>
    #include<cstdio>
    #include<cstdlib>
    #include<cstring>
    #include<iostream>
    #include<algorithm>
    using namespace std;

    struct food{int v,m,c;}g[55];
    int n,m,v,f[405][405];

    int main()
    {
    scanf("%d%d%d",&v,&m,&n);
    for(int i=1;i<=n;i++)
    scanf("%d%d%d",&g[i].v,&g[i].m,&g[i].c);
    for(int i=1;i<=n;i++)
    for(int j=v;j>=g[i].v;j--)
    for(int k=m;k>=g[i].m;k--)
    f[j][k]=max(f[j][k],f[j-g[i].v][k-g[i].m]+g[i].c);
    printf("%d\n",f[v][m]);
    return 0;
    }

  • 0
    @ 2014-08-21 16:58:57

    #include<iostream>
    #include<cstdio>
    #include<cstdlib>
    using namespace std;
    int V, W, N, f[410][410], vv[55], ww[55], cc[55];
    int main()
    {
    scanf("%d%d%d", &V, &W, &N);

    for(int i = 1; i <= N; i++) cin >> vv[i] >> ww[i] >> cc[i];

    for(int i = 1; i <= N; i++)
    for(int j = V; j >= vv[i]; j--)
    for(int k = W; k >= ww[i]; k--)
    if(f[j - vv[i]][k - ww[i]] + cc[i] > f[j][k])
    f[j][k] = f[j - vv[i]][k - ww[i]] + cc[i];

    cout << f[V][W] << endl;
    return 0;
    }

  • 0
    @ 2013-11-08 09:04:45

    var
    a,b,s:array[0..50] of longint;
    f:array[0..400,0..400] of longint;
    n,v,m,i,j,k:longint;
    begin
    readln(v,m);
    readln(n);
    for i:=1 to n do
    readln(a[i],b[i],s[i]);
    for i:=1 to n do
    for j:=v downto a[i] do
    for k:=m downto b[i] do
    if f[j-a[i],k-b[i]]+s[i]>f[j,k] then f[j,k]:=f[j-a[i],k-b[i]]+s[i];
    writeln(f[v,m]);
    end.
    现在每做一道题,写一份题解,
    但这个太水了
    不写了

  • 0
    @ 2013-10-15 15:15:31

    #include <iostream>
    //#include <memory.h>

    using namespace std;

    const int MAX_SIZE = 1000;

    int v[MAX_SIZE] = {0}, m[MAX_SIZE] = {0}, c[MAX_SIZE] = {0}, Calorie[MAX_SIZE][MAX_SIZE];

    int main()
    {
    //
    // 清零操作(可忽略)
    //
    //memset(Calorie, 0, MAX_SIZE * MAX_SIZE * sizeof(int));

    //
    // 输入数据
    //
    int volumeMax, weightMax, N;
    cin >> volumeMax >> weightMax;
    cin >> N;

    //
    // 读入每个食物的体积、质量和所含卡路里
    //
    int i, j, k;
    for (i = 1; i <= N; i++) {
    cin >> v[i] >> m[i] >> c[i];
    }

    //
    // 背包DP
    //
    for (i = 1; i <= N; i++) {
    for (j = volumeMax; j >= v[i]; j--) {
    for (k = weightMax; k >= m[i]; k--) {
    if (Calorie[j - v[i]][k - m[i]] + c[i] > Calorie[j][k]) {
    Calorie[j][k] = Calorie[j - v[i]][k - m[i]] + c[i];
    }
    }
    }
    }

    //
    // 输出结果
    //
    cout << Calorie[volumeMax][weightMax];

    return 0;
    }

信息

ID
1334
难度
2
分类
动态规划 | 背包 点击显示
标签
(无)
递交数
2920
已通过
1747
通过率
60%
被复制
5
上传者