题解

203 条题解

  • 0
    @ 2009-08-13 10:48:12

    为什么我同样一个程序,前三次是0分,后两次是AC呢?

  • 0
    @ 2009-08-11 00:17:48

    编译通过...

    ├ 测试数据 01:答案正确... 0ms

    ├ 测试数据 02:答案正确... 0ms

    ├ 测试数据 03:答案正确... 0ms

    ├ 测试数据 04:答案正确... 0ms

    ├ 测试数据 05:答案正确... 0ms

    ├ 测试数据 06:答案正确... 0ms

    ├ 测试数据 07:答案正确... 0ms

    ├ 测试数据 08:答案正确... 0ms

    ├ 测试数据 09:答案正确... 0ms

    ├ 测试数据 10:答案正确... 0ms

    ---|---|---|---|---|---|---|---|-

    Accepted 有效得分:100 有效耗时:0ms

    var

    a,b:array[0..26] of longint;

    f:array[0..30000] of longint;

    n,m,i,j,o:longint;

    begin

    readln(n,m);

    for i:=1 to m do

    readln(a[i],b[i]);

    for i:=1 to m do

    for j:=n downto 1 do

    if (j-a[i]>=0)and(f[j-a[i]]+a[i]*b[i]>f[j]) then f[j]:=f[j-a[i]]+a[i]*b[i];

    write(f[n]);

    end.

    DP做。。。01背包的变种。。。

  • 0
    @ 2009-08-07 19:13:37

    14行的精简小程序…………

  • 0
    @ 2009-08-06 15:40:28

    背包小的变种。

    #include

    #define M 30000

    int f[M+1],v[26],p[26];

    int max(int a,int b)

    {

    return (a > b) ? a : b;

    }

    int main()

    {

    int n,m;

    int i,j;

    scanf("%d %d",&n,&m);

    for(i = 1;i =0)

    f[j] = max(f[j],f[j-v[i]]+v[i]*p[i]);

    }

    }

    printf("%d",f[n]);

    return 0;

    }

  • 0
    @ 2009-08-05 14:38:20

    这是什么背包啊?0—1 还是完全??

  • 0
    @ 2009-08-02 09:50:27

    #include

    using namespace std;

    int a[30001],f[3000001]={0},b[30001];

    int main(void)

    {

    int m,n,i,j;

    cin>>n>>m;

    for(i=1;i>a[i]>>b[i];

    for(i=1;i0;j--)

    if(j>a[i])

    f[j]=max(f[j],f[j-a[i]]+b[i]*a[i]);

    cout

  • 0
    @ 2009-08-01 08:39:41

    var

    v,n,i,j,k:integer;

    a,c,b:array[0..30000] of longint;

    begin

    readln(v,n);

    for i:=1 to n do

    begin

    readln(a[i],k);

    b[i]:=a[i]*k;

    for j:=v-a[i] downto 0 do

    if c[j]+b[i]>c[j+a[i]] then

    c[j+a[i]]:=c[j]+b[i];

    end;

    write(c[v]);

    end.

  • 0
    @ 2009-07-27 17:04:36

    编译通过...

    ├ 测试数据 01:答案正确... 0ms

    ├ 测试数据 02:答案正确... 0ms

    ├ 测试数据 03:答案正确... 0ms

    ├ 测试数据 04:答案正确... 0ms

    ├ 测试数据 05:答案正确... 0ms

    ├ 测试数据 06:答案正确... 0ms

    ├ 测试数据 07:答案正确... 0ms

    ├ 测试数据 08:答案正确... 0ms

    ├ 测试数据 09:答案正确... 0ms

    ├ 测试数据 10:答案正确... 0ms

    ---|---|---|---|---|---|---|---|-

    Accepted 有效得分:100 有效耗时:0ms

    var i,j,m,n,max:longint; f,v,p:array[-100000..100000]of longint;

    begin

    readln(m,n);

    for i:=1 to n do readln(v[i],p[i]);

    for i:=1 to n do

    for j:=m downto 1 do

    begin

    if (j>=v[i])and(f[j-v[i]]+v[i]*p[i]>f[j]) then

    f[j]:=f[j-v[i]]+v[i]*p[i];

    if f[j]>max then max:=f[j];

    end;

    write(max);

    end.

    怎么是0/1背包?

    看题意是完全背包..提交了2次AC

  • 0
    @ 2009-07-24 22:20:39

    一次AC

    编译通过...

    ├ 测试数据 01:答案正确... 0ms

    ├ 测试数据 02:答案正确... 0ms

    ├ 测试数据 03:答案正确... 0ms

    ├ 测试数据 04:答案正确... 0ms

    ├ 测试数据 05:答案正确... 0ms

    ├ 测试数据 06:答案正确... 0ms

    ├ 测试数据 07:答案正确... 0ms

    ├ 测试数据 08:答案正确... 0ms

    ├ 测试数据 09:答案正确... 25ms

    ├ 测试数据 10:答案正确... 0ms

    ---|---|---|---|---|---|---|---|-

    Accepted 有效得分:100 有效耗时:25ms

    var n,m,a:longint;

    s:array[1..25,1..2] of longint;

    function dg(no,max,left:longint):longint;

    var p,c,d:longint;

    begin

    p:=no;

    while pm+1 do

    begin

    if leftd then exit(c)

    else exit(d);

    end;

    end;

    exit(max);

    end;

    begin

    readln(n,m);

    for a:=1 to m do

    readln(s[a,1],s[a,2]);

    write(dg(1,0,n));

    end.

  • 0
    @ 2009-07-24 15:19:58

    01背包罢了

    var

    i,j,k,n,m:longint;

    v,w:array[1..25] of longint;

    f:array[0..30000] of longint;

    begin

    read(n,m);

    for i:=1 to m do

    begin

    read(v[i],k);

    w[i]:=k*v[i];

    end;

    for i:=1 to m do

    for j:=n downto v[i] do

    if f[j]k then k:=f[i];

    write(k);

    end.

  • 0
    @ 2009-07-19 16:10:40

    program dsa;

    var n,m,i,t,p,sv,s:integer;

      svp,svpmax:longint;

      v,w:array[1..25] of integer;

      vp:array[1..25] of longint;

    begin

    read(n,m);

    for i:=1 to m do

      begin

       read(t);

       v[i]:=t;

       read(t);

       vp[i]:=v[i]*t;

      end;

    p:=0;s:=0;svp:=0;sv:=0;svpmax:=0;

    repeat

      inc(p);

      if p>m then

       begin

        p:=w;

        sv:=sv-v[p];

        svp:=svp-vp[p];

        dec(s);

       end

      else if sv+v[p]svpmax then svpmax:=svp;

       end;

    until (s=0) and (p=m);

    write(svpmax);

    end.

  • 0
    @ 2009-07-15 16:50:43

    program dsa;

    var n,m,i,t,p,sv,s:integer;

    svp,svpmax:longint;

    v,w:array[1..25] of integer;

    vp:array[1..25] of longint;

    begin

    read(n,m);

    for i:=1 to m do

    begin

    read(t);

    v[i]:=t;

    read(t);

    vp[i]:=v[i]*t;

    end;

    p:=0;s:=0;svp:=0;sv:=0;svpmax:=0;

    repeat

    inc(p);

    if p>m then

    begin

    p:=w;

    sv:=sv-v[p];

    svp:=svp-vp[p];

    dec(s);

    end

    else if sv+v[p]svpmax then svpmax:=svp;

    end;

    until (s=0) and (p=m);

    write(svpmax);

    end.

  • 0
    @ 2009-07-14 15:29:48

    #include

    long a[1005];

    int main()

    {

    long n,m,i,j,x,y;

    scanf("%d %d",&n,&m);

    for(i=1;i=x;j--)

    if(a[j]

  • 0
    @ 2009-07-12 15:58:41

    采药的翻版!

  • 0
    @ 2009-07-12 09:47:15

    var a,v,w:array [0..50] of longint;

    f:array [0..200000] of longint;

    i,j,k,l,m,n,b,o,s,sum:longint;

    begin

    readln(n,m);

    for i:=1 to m do

    readln(v[i],w[i]);

    fillchar(f,sizeof(f),0);

    for i:=1 to m do

    a[i]:=v[i]*w[i];

    s:=0;

    for i:=1 to m do begin

    inc(s,v[i]);

    for j:=s downto v[i] do

    if f[j-v[i]]+a[i]>f[j] then f[j]:=f[j-v[i]]+a[i];

    end;

    for i:=1 to n do

    if f[i]>f[0] then f[0]:=f[i];

    writeln(f[0]);

    end.

  • 0
    @ 2009-07-12 09:36:52

    program mm;

    var

    a:array[0..40] of record

    x,y:longint;

    end;

    i,j,k,l,m,n,z,money:Longint;

    f:array[0..30050] of longint;

    sum:array[0..50] of longint;

    begin

    fillchar(f,sizeof(f),0);

    fillchar(a,sizeof(a),0);

    fillchar(sum,sizeof(sum),0);

    readln(money,n);

    for i:=1 to n do

    read(a[i].x,a[i].y);

    for i:=1 to n-1 do

    for j:=1 to n-i do

    if a[j].x>a[j+1].x then begin

    a[0]:=a[j];

    a[j]:=a[j+1];

    a[j+1]:=a[0];

    end;

    for i:=1 to n do

    sum[i]:=sum+a[i].x;

    for j:=1 to n do begin

    if sum[j]>money then sum[j]:=money;

    for i:=sum[j] downto a[j].x do

    if f[i-a[j].x]+a[j].x*a[j].y>f[i] then

    f[i]:=f[i-a[j].x]+a[j].x*a[j].y;

    end;

    for i:=money downto 1 do

    if f[i]>f[0] then f[0]:=f[i];

    writeln(f[0]);

    end.

  • 0
    @ 2009-07-10 08:53:11

    var max,k,j,n,m:longint;

    v,w,z:array[1..3000]of longint;

    x:array[0..3000,0..3000]of longint;

    begin

    readln(n,m);

    for j:=1 to m do begin

    readln(v[j],w[j]);

    z[j]:=v[j]*w[j];

    end;

    for k:=0 to n do x[0,k]:=0;

    for j:=0 to m do x[j,0]:=0;

    for k:=1 to m do

    for j:=1 to n do begin

    x[k,j]:=x[k-1,j];

    if (v[k]x[k,j]) then

    x[k,j]:=x[k-1,j-v[k]]+z[k];

    end;

    max:=x[m,1];

    for j:=1 to n do if x[m,j]>max then max:=x[m,j];

    writeln(max);

    end.

  • 0
    @ 2009-09-13 12:34:35

    编译通过...

    ├ 测试数据 01:答案正确... 0ms

    ├ 测试数据 02:答案正确... 0ms

    ├ 测试数据 03:答案正确... 0ms

    ├ 测试数据 04:答案正确... 0ms

    ├ 测试数据 05:答案正确... 0ms

    ├ 测试数据 06:答案正确... 0ms

    ├ 测试数据 07:答案正确... 0ms

    ├ 测试数据 08:答案正确... 0ms

    ├ 测试数据 09:答案正确... 0ms

    ├ 测试数据 10:答案正确... 0ms

    ---|---|---|---|---|---|---|---|-

    Accepted 有效得分:100 有效耗时:0ms

    program p1317;

    var

    a,b:array[1..25] of longint;

    f:array[0..30000] of longint;

    i,j,k,l,m,n,o,p,q:longint;

    function max(x,y:longint):longint;

    begin

    if x>y then exit(x)

    else exit(y);

    end;

    begin

    readln(n,m);

    for i:=1 to m do

    readln(a[i],b[i]);

    for i:=1 to m do

    for j:=n downto a[i] do

    f[j]:=max(f[j],f[j-a[i]]+a[i]*b[i]);

    writeln(f[n]);

    end.

  • 0
    @ 2009-07-01 09:00:38

    //开心的金明

    #include

    int N=0, m=0; //N为最大价格

    int v[25+1], p[25+1]; //v价格 p重要度

    int temp[25+1][30000+1]={0};

    int max(int a, int b)

    {

    if(a>b) return a;

    else return b;

    }

    int main()

    {

    //init

    int i, j;

    scanf("%d %d", &N, &m);

    for(i=1; i

  • 0
    @ 2009-06-23 11:44:03

    program p1317;

    var a,b:array[1..25] of longint;

    f:array[0..30000] of longint;

    i,j,k,l,m,n,o,p,q:longint;

    function max(x,y:longint):longint;

    begin if x>y then exit(x) else exit(y);end;

    begin

    readln(n,m);

    for i:=1 to m do

    readln(a[i],b[i]);

    for i:=1 to m do

    for j:=n downto a[i] do

    f[j]:=max(f[j],f[j-a[i]]+a[i]*b[i]);

    writeln(f[n]);

    end.

信息

ID
1317
难度
3
分类
动态规划 | 背包 点击显示
标签
递交数
6628
已通过
3339
通过率
50%
被复制
31
上传者