239 条题解
-
0code-geass LV 9 @ 2009-08-04 13:27:42
program li;
var i,j,v,n:longint;
a:array[0..1000]of longint;
f:array[0..20000]of longint;
function max(a,b:longint):longint;
begin
if a>b then exit(a) else exit(b);
end;
begin
readln(v);
readln(n);
for i:=1 to n do read(a[i]);for i:=1 to n do
for j:=v downto a[i] do
f[j]:=max(f[j-a[i]]+a[i],f[j]);writeln(v-f[v]);
end...........竟然交了N次这种水题............
-
02009-08-02 19:09:57@
发一个简单明了的C++程序!!方便学C++的!!
#include
using namespace std;
int main()
{
int v,n;
bool f[20001];
int a[31];
cin>>v>>n;
for(int i=1;i>a[i];
memset(f,0,sizeof(f));
f[0]=1;
for(int i=1;i=a[i];j--)
{
if(f[j-a[i]]||f[j])
f[j]=1;
else
f[j]=0;}
for(int k=v;k>=0;k--)
{
if(f[k]){
cout -
02009-08-01 18:03:43@
只能取一次,LZ中文太好 若“千”
-
02009-08-01 10:26:15@
15行……
-
02009-07-31 14:04:44@
发现一片大海 囧
-
02009-07-27 23:00:16@
var
a :array[1..30]of longint;
v :longint;
n :longint;
i,j :longint;
t :longint;
visit :array[0..30,0..20000]of longint;
function f(n,v:longint):longint;
begin
if visit[n][v]0 then begin f:=visit[n][v];exit; end;if (n
-
02009-07-26 20:56:07@
最简单的背包
-
02009-07-25 15:41:20@
var
b,c,n,i,lv:integer;
f,v:array[0..20000] of integer;
begin
readln(lv);
readln(n);
fillchar(f,sizeof(f),0);
f[lv]:=1;
for i:=1 to n do
readln(v[i]);
for i:=1 to n do
for c:=v[i] to lv do
begin
if (f[c]=1) then f[c-v[i]]:=1;
end;
for i:=0 to lv do
if f[i]=1 then begin writeln(i);break; end;
end. -
02009-07-24 15:09:46@
program zhuangxiang;
var
v,n,i,j,x:integer;
a,b:array[0..30] of integer;
begin
read(v);
read(n);
for i:=1 to n do
read(a[i]);
for j:=1 to n do
b[j]:=v;
for j:=1 to n do
for i:=j to n do
begin
if b[j]>=a[i] then
b[j]:=b[j]-a[i];
if b[j] -
02009-07-18 11:42:07@
搜索照过~!~
小小的剪枝~!~
秒杀~!~var
v,n,i,j,min,y,k:longint;
a,s:array[1..31] of longint;
dd:array[1..30] of boolean;
procedure dfs(t,x:longint);
begin
if x=0 then begin write(0); halt; end;
if x=min then exit;
if x-s[t]>=0 then dfs(n+1,x-s[t])
else
if (not dd[t]) and (x>=a[t]) then
begin
dd[t]:=true;
dfs(t+1,x-a[t]);
dd[t]:=false;
end;
dfs(t+1,x);
end;Begin
readln(v);
readln(n);
for i:=1 to n do read(a[i]);
i:=1;
while iv then
begin
y:=a[n];
a[n]:=a[i];
a[i]:=y;
dec(n);
end;
inc(i);
end;for i:=1 to n-1 do
begin
k:=i;
for j:=i+1 to n do if a[k] -
02009-07-16 15:12:50@
program dsa;
var
i,j,k,l,m,n,s:longint;
a:array[1..1000] of longint;
f:array[0..30,0..20000] of longint;
begin
readln(m,n);
for i:=1 to n do read(a[i]);
for i:=1 to n do
for j:=1 to m do
if (j>=a[i]) and (f -
02009-07-16 14:37:04@
01背包的简单变形
每个物品的价值就是其耗费 -
02009-07-09 21:50:33@
var f,w:array[0..30000]of longint; n,v,i,j,max:longint;
begin
readln(v);
readln(n);
for i:=1 to n do readln(w[i]);
for i:=1 to n do
begin
for j:=v downto w[i] do
if f[j-w[i]]+w[i]>f[j] then f[j]:=f[j-w[i]]+w[i];
end;
max:=0;
for i:=1 to v do if f[i]>max then max:=f[i];
write(v-f[i]);
end.
一次AC -
02009-07-09 16:03:41@
苍天啊,大地啊,我最近有干过什么-RP的事吗?我把输入格式搞错了,平时做时箱子体积都是同一行输入,搞得我这次也是同一行输入,害我WA了3次!我的AC率啊!!!
为纪念我的AC率,默哀3毫秒! -
02009-11-06 20:07:25@
var
i,j,v,n,s:longint;
f:array[0..20000]of boolean;
a:array[0..30]of longint;
begin
readln(v);
readln(n);
for i:=1 to n do
readln(a[i]);
fillchar(f,sizeof(f),0);
f[0]:=true;
s:=0;
for i:=1 to n do
begin
inc(s,a[i]);
if s>v then s:=v;
for j:=s downto a[i] do
f[j]:=f[j] or f[j-a[i]];
end;
for i:=v downto 0 do
if f[i] then break;
writeln(v-i);
end.AC...
-
02009-07-03 16:03:38@
编译通过...
├ 测试数据 01:答案正确... 0ms
├ 测试数据 02:答案正确... 0ms
├ 测试数据 03:答案正确... 0ms
├ 测试数据 04:答案正确... 0ms
├ 测试数据 05:答案正确... 0ms
---|---|---|---|---|---|---|---|-
Accepted 有效得分:100 有效耗时:0ms
var f:array [0..30003] of boolean;
a:array [0..40] of longint;
v,n,i,j,k,l,o,p,s,s2:longint;
begin
readln(v);
readln(n);
fillchar(f,sizeof(f),false);
f[0]:=true;
for i:=1 to n do
readln(a[i]);
for i:=1 to n-1 do
for j:=1 to n-i do
if a[j]>a[j-1] then begin
a[0]:=a[j];
a[j]:=a[j+1];
a[j+1]:=a[0];
end;
for i:=1 to n do begin
inc(s,a[i]);
if v -
02009-07-01 17:50:48@
program sdf;
var
v,ss,k,i,j,n,mm,x:longint;
a:array[0..1000] of integer;
f,g:array[0..20000] of boolean;
begin
readln(v);
readln(n);
fillchar(f,sizeof(f),false);
for i:=1 to n do begin
readln(a[i]);
end;
for i:=1 to n-1 do
for j:=1 to n-i do
if a[j]>a[j+1] then begin
a[0]:=a[j];
a[j]:=a[j+1];
a[j+1]:=a[0];
end;
f[0]:=true;
for i:=1 to n do begin
inc(ss,a[i]);
if ss -
02009-07-01 17:23:16@
var f,g:array [0..30000] of boolean;
V,N,i,j,k,o,l,p,s:longint;
a:array [0..30000] of longint;
begin
readln(v);
readln(n);
fillchar(f,sizeof(f),false);
f[0]:=true;
for i:=1 to n do
readln(a[i]);
for i:=1 to n-1 do
for j:=1 to n-i do
if a[i]>a[j] then begin
p:=a[i];
a[i]:=a[j];
a[j]:=p;
end;
for i:=1 to n do begin
inc(s,a[i]);
if v -
02009-06-09 12:17:39@
var a,b:array[1..100000] of longint;
i,j,k,l,m,n,v,c,x,z,q,w,e,s:longint;
procedure f(q,w:longint);
var i,j:longint;
begin
if q=0 then f(q-a[i],i);
b[i]:=0;
end;
if (q-a[n]>=0) and (a[n]0) then q:=q-a[n];
end;begin
readln(v);
readln(n);
for i:=1 to n do readln(a[i]);
m:=maxlongint;
f(v,0);
writeln(m);
end. -
02009-05-23 19:52:49@
const maxn=20001;
var f:array[0..maxn]of longint;
c,v,t,n,k,j:longint;
begin
readln(t);
readln(n);
for n:=1 to n do begin
readln(c);
for j:=t downto c do
if f[j-c]+c>f[j]then f[j]:=f[j-c]+c;
end;
writeln(t-f[t]);
end.