题解

239 条题解

  • 0
    @ 2009-10-08 20:29:19

    #include

    int f[31][20001];

    int main(void)

    {

    int i,j,v,n,a[31];

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

    for (i=1;i

  • 0
    @ 2009-10-05 13:58:30

    编译通过...

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

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

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

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

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

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

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

    #include

    int main(){

    int n, vol, volume[200], ans[21000] = {0};

    int i, j;

    scanf("%d", &vol);

    scanf("%d", &n);

    for(i = 1; i b)

    return a;

    return b;

    }

  • 0
    @ 2009-09-20 15:02:48

    编译通过...

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

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

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

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

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

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

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

    var

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

    f:array[0..20000] of boolean;

    begin

    fillchar(f,sizeof(f),false);

    f[0]:=true;

    readln(m);

    readln(n);

    for i:=1 to n do

    begin

    readln(v);

    for j:=m downto v do

    if f[j-v] then

    f[j]:=true;

    end;

    i:=m;

    while not f[i] do

    dec(i);

    writeln(m-i);

    end.

    var

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

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

    begin

    readln(m);

    readln(n);

    for i:=1 to n do

    begin

    readln(v);

    for j:=m downto v do

    if f[j-v]+v>f[j] then

    f[j]:=f[j-v]+v;

    end;

    writeln(m-f[m]);

    end.

    Flag    Accepted

    题号   P1133

    类型(?)   动态规划

    通过   5389人

    提交   13114次

    通过率   41%

    难度   2

    提交 讨论 题解

  • 0
    @ 2009-09-18 17:26:08
  • 0
    @ 2009-09-16 18:54:00

    发现了一件很诡异的事情。。。

    编译通过...

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

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

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

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

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

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

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

    var

    f:array[0..20000]of boolean;

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

    w:array[1..30]of longint;

    begin

    readln(v,n);

    for i:=1 to n do

    read(w[i]);

    f[v]:=true;

    for i:=1 to n do

    for j:=w[i] to v do {---|->为什么当这句是for j:=v downto w[i]do 是不对的?有没有大牛帮忙讲一下,本姑娘很菜……}

    if f[j] then f[j-w[i]]:=true;

    i:=0;

    while not(f[i])do inc(i);

    writeln(i);

    end.

  • 0
    @ 2009-09-12 19:36:05

    var

    x,y,i,j,m,n:longint;

    f,v:array[0..20000]of longint;

    begin

    readln(m);

    readln(n);

    for i:=1 to n do

    readln(v[i]);

    for i:=1 to n do

    for j:=m downto 1 do

    if j>=v[i] then begin

    if f[j]

  • 0
    @ 2009-09-08 21:52:00

    3ci AC~~~......

  • 0
    @ 2009-09-08 08:18:11

    求组合最大数

    program project1;

    var

    a:array[0..30] of integer;

    f:array[0..20000] of boolean;

    n,i,j,v:integer;

    begin

    readln(v);

    readln(n);

    for i:=1 to n do

    read(a[i]); f[0]:=true;

    for i:=1 to n do

    for j:=v downto a[i] do

    if f[j-a[i]] then f[j]:=true;

    for i:=v downto 0 do

    if f[i] then begin write(v-i); break; end;

    end.

  • 0
    @ 2009-09-06 16:14:08

    var

    x:array[0..20000] of boolean;

    i,v,j,t,n,m:longint;

    begin

    readln(v);readln(n);

    fillchar(x,sizeof(x),false);

    x[0]:=true;

    m:=0;

    for i:=1 to n do

    begin

    readln(t);

    for j:=m downto 0 do

    begin

    if x[j]and(t+jm then m:=t+j;

    end;

    end;

    end;

    for i:=v downto 0 do

    if x[i]=true then

    begin writeln(v-i);break;end;

    end.

  • 0
    @ 2009-09-05 18:25:15

    编译通过...

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

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

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

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

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

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

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

    传说中的0-1

  • 0
    @ 2009-08-27 22:18:32

    var

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

    w,c:array[0..10000] of longint;

    n,i,j,x,v:longint;

    begin

    readln(v);

    readln(n);

    for i:=1 to n do readln(w[i]);

    for i:=1 to n do c[i]:=w[i];

    for i:=1 to n do

    for x:=v downto w[i] do

    if f[x-w[i]]+c[i]>f[x] then f[x]:=f[x-w[i]]+c[i];

    writeln(v-f[v]);

    end.

    编译通过...

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

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

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

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

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

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

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

  • 0
    @ 2009-08-25 18:01:31

    program P1133(input,output);

    var

    f:array [0..40000] of boolean;

    v:array [1..30] of longint;

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

    begin

    readln(max);

    readln(n);

    for i:=1 to n do

    readln(v[i]);

    fillchar(f,sizeof(f),false);

    k:=1;

    f[0]:=true;

    while (not f[max]) and (k

  • 0
    @ 2009-08-19 10:10:03

    注意数组开到20000

    因为这个交了好几次都是0分

    编译通过...

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

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

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

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

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

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

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

    program ex68;

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

    f0,f1:array[0..20000]of boolean;

    x:array[0..20000]of integer;

    begin

    readln(v);

    readln(n);

    for i:=1 to n do readln(x[i]);

    fillchar(f0,sizeof(f0),0);

    f0[0]:=true;

    for i:=1 to n do

    begin

    f1:=f0;

    if x[i]>v then continue;

    for j:=x[i] to v do

    if f0[j-x[i]] then f1[j]:=true;

    f0:=f1;

    end;

    for k:=v downto 0 do

    if f1[k] then

    begin

    writeln(v-k); halt;

    end;

    end.

  • 0
    @ 2009-08-17 16:45:57

    我这个叫做超级复杂的方法,嘻嘻~~~

    背包,居然都过了!

    AC,yes!!!

    program p1133;

    var

    a:array[0..100000] of longint;

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

    v:array[1..30] of longint;

    rubbish:string;

    function max(a,b:longint):longint;

    begin

    if a>b then exit(a);

    exit(b);

    end;

    begin

    read(volum,n);

    for i:=1 to n do

    read(v[i]);

    a[0]:=0;

    for i:=1 to n do

    begin

    for j:=volum downto v[i] do

    a[j]:=max(a[j],a[j-v[i]]+v[i]);

    end;

    for i:=volum downto 1 do

    if a[i]=i then begin j:=i; break; end;

    writeln(volum-i);

    rubbish:='I am the best!!!!!Yes,Yes!! I can Ac!'

    end.

  • 0
    @ 2009-08-13 16:12:44

    var

    a:array[0..30] of longint;

    p:array[0..20000] of boolean;

    n,v,c,min,t,i,j,max:longint;

    begin

    max:=0;

    readln(v);

    readln(n);

    for i:=1 to n do

    read(a[i]);

    readln;

    p[0]:=true;

    for i:=1 to n do

    for j:=v downto a[i] do

    begin

    p[j]:=p[j-a[i]] or p[j];

    if (max

  • 0
    @ 2009-08-13 16:43:27

    var

    max,n,i,j,out:integer;

    f:array[0..20000,0..30] of integer;

    v:array[1..30] of integer;

    begin

    readln(max);

    readln(n);

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

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

    for j:=1 to n do

    for i:=1 to max do

    begin

    f:=f;

    if (i>=v[j]) and (f[i-v[j],j-1]+v[j]>f) then

    f:=f[i-v[j],j-1]+v[j]

    end;

    out:=max-f[max,n];

    write(out);

    end.

    對的,,,

  • 0
    @ 2009-08-13 09:33:39

    C++~~~

    #include

    int a[20002], dp[20002];

    inline int fmax(int i, int j)

    {

    return i>j?i:j ;

    }

    int main()

    {

    int v, n, i, j, *p, *pp;

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

    for( p=&a[1], pp=&a[n]+1; p=a[i]; j-- )

    dp[j]=fmax(dp[j], dp[j-a[i]]+a[i]);

    printf("%d\n", v-dp[v]);

    return 0;

    }

  • 0
    @ 2009-08-10 21:27:57

    var

    a:array[1..30] of longint;

    f:array[0..31,0..20000] of longint;

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

    begin

    readln(n);

    readln(m);

    for i:=1 to m do

    readln(a[i]);

    for i:=1 to m do

    for j:=1 to n do

    if (j-a[i]>=0)and(f

  • 0
    @ 2009-08-06 22:53:32

    ....

    把数组开太小

    交了3便

  • 0
    @ 2009-08-06 22:11:07

    Flag    Accepted

    题号   P1133

    类型(?)   动态规划

    通过   5000人

    提交   12163次

    通过率   41%

    难度   2

    第5000个AC

信息

ID
1133
难度
4
分类
动态规划 | 背包 点击显示
标签
递交数
10782
已通过
4479
通过率
42%
被复制
24
上传者