总结
据悉一等分数线:300
实际得分:50+100+30+30
策略得分:50+100+30+100
题目: | 采药 | |
题目大意: | N个物品,获得物品耗时T,价值V,求在M时间内的能获得的最大价值 | |
数据范围: | N,M<=100000,T,V<=10 | |
样例: | 3 9 10 10 8 1 1 2 | 3 |
做题思路: | 如果还按0/1背包做的话能得50分。 正解是多重背包(因为T,V很小)+队列优化 | |
知识点: | 多重背包 |
var
a:array[0..10,0..10]of longint;
f,d,g:array[0..100000]oflongint;
j,k,p,head,tail,tmp,w,n,m:longint;
//==============================================
procedure init;
var
i,t,v:longint;
begin
readln(n,m);
fori:=1 to n do
begin
readln(t,v);
ift=0 then inc(tmp,v){<预处理耗时为0的,不知数据有没有这样的>}
else inc(a[t,v]);
end;
end;
//==============================================
procedure dp;
var
v,w,i,j,head,tail:longint;
begin
forv:=1 to 10 do
forw:=1 to 10 do{<枚举耗时和价值,得到同耗时同价值物品的数量a[v,w]>}
begin
ifa[v,w]=0 then continue;
for i:=0 to v-1 do
begin
j:=i;
head:=1;tail:=1;
d[1]:=j;
g[1]:=f[j];
inc(j,v);
while j<=m do
begin
while tail>=head do
if f[j]>=g[tail]+(j-d[tail])div v*w then dec(tail)
else break;
inc(tail);
d[tail]:=j;
g[tail]:=f[j];
f[j]:=g[head]+(j-d[head])div v*w;
if d[head]+v*a[v,w]=j then inc(head);
inc(j,v);
end;
end;
end;
end;
//=================================================
begin
assign(input,'medic.in');reset(input);
assign(output,'medic.out');rewrite(output);
init;
dp;
writeln(f[m]+tmp);
close(input);close(output);
end.
题目: | 方格取数 | |
题目大意: | N*M的矩阵,每个矩阵里有值(正整数),求从(1,1)到(N,M)路径上所有数的乘积的末尾0最少为多少 | |
数据范围: | 1<N,M<=1000 | |
样例: | 3 3 1 2 3 10 5 100 10 8 9 | 1 |
做题思路: | 先处理矩阵中的数,将其分为2和5(因为0是由*10得到的,而10是由2*5得到的,所以路径上最少的2*或者5*就是最后的答案) f1[i,j]=min(f1[i-1,j],f1[i,j-1])+a1[i,j] f2[i,j]=min(f2[i-1,j],f2[i,j-1])+a2[i,j] ans=max(f1[n,m],f2[n,m]) 证:若5和2的路径并非一条,则除5的那条以外没有更优的5路径,除2的那条意外没有更优2的路径,所以从中选取5和2依旧最优; 若5和2来自同一条路径,则构成10的必然为最少的5或者2(单独一个不能构成10) | |
知识点: | 动态规划、预处理 |
var
a1,a2,f1,f2:array[0..1000,0..1000]of longint;
n,m,i,j,x,t:longint;
//==================================================
function min(a,b:longint):longint;
begin
ifa>b then exit(b);exit(a);
end;
//==================================================
begin
assign(input,'matrix.in');reset(input);
assign(output,'matrix.out');rewrite(output);
readln(n,m);
fori:=1 to n do
begin
forj:=1 to m do
begin
read(x);
t:=x;
while t mod 2=0 do{<求该正整数包含的5/2的个数>}
begin
inc(a1[i,j]);
t:=t div 2;
end;
t:=x;
while t mod 5=0 do
begin
inc(a2[i,j]);
t:=t div 5;
end;
end;
readln;
end;
fillchar(f1,sizeof(f1),100);
fillchar(f2,sizeof(f2),100);
f1[0,1]:=0;f1[1,0]:=0;
f2[0,1]:=0;f2[1,0]:=0;
fori:=1 to n do
forj:=1 to m do
begin
f1[i,j]:=min(f1[i-1,j],f1[i,j-1])+a1[i,j];
f2[i,j]:=min(f2[i-1,j],f2[i,j-1])+a2[i,j];
end;
writeln(min(f1[n,m],f2[n,m]));
close(input);close(output);
end.
题目: | 统计 | |
题目大意: | 求{1,2,3..N}的全排列中,正好包含M对逆序对的排列个数,最后将答案mod 124567 | |
数据范围: | 0<N,M<=1000 | |
样例: | 3 1 | 2 |
做题思路: | 枚举全排列然后求逆序对复杂度很高,只能得30分。 这题是动态规划 f[i,j]表示前i个数的排列中,逆序对为j的方案数。 这让我想到了序关系计数 转移:枚举第i个数的插入位置 优化:前缀和加速(不晓得原理) | |
知识点: | 动态规划、优化 |
const
mo=124567;
var
f,sum:array[0..1010,0..1010]of longint;
i,j,n,m:longint;
begin
assign(input,'count.in');reset(input);
assign(output,'count.out');rewrite(output);
readln(n,m);
fillchar(f,sizeof(f),0);
f[1,0]:=1;
fori:=0 to m do sum[1,i]:=1;{<sum数组貌似就是求的位置差,类似于树状数组就逆序对>}
fori:=2 to n do
begin
forj:=0 to m do
begin
ifj<=i-1 then f[i,j]:=sum[i-1,j]{<如果j<i-1说明逆序对数没有增加>}
else f[i,j]:=sum[i-1,j]-sum[i-1,j-i];{<大的-小的>}
iff[i,j]<0 then inc(f[i,j],mo);
end;
sum[i,0]:=f[i,0];
forj:=1 to m do sum[i,j]:=(sum[i,j-1]+f[i,j])mod mo;{<优化>}
end;
writeln(f[n,m]);
close(input);close(output);
end.
题目: | 直角三角形 | |
题目大意: | 给定N个点坐标,求由其构成的直角边平行坐标系的直角三角形个数 | |
数据范围: | 0<N<=100000 | |
样例: | 4 0 0 0 1 1 0 1 1 | 4 |
做题思路: | 枚举的话30分 快排后二分查找x相等的、y相等的然后 ans+(sumx-1)*(sumy-1) | |
知识点: | 快排、二分查找 |
type
act=record
x,y:longint;
end;
var
ax,ay,a:array[0..100010]of act;
n,i,j,k,ans,l,r,t:longint;
//==============================================
procedure qsortx(l,r:longint);
var
i,j,k:longint;
t:act;
begin
i:=l;j:=r;
k:=ax[(i+j)shr 1].x;
repeat
whileax[i].x<k do inc(i);
whileax[j].x>k do dec(j);
ifi<=j then
begin
t:=ax[i];ax[i]:=ax[j];ax[j]:=t;
inc(i);dec(j);
end;
untili>j;
ifi<r then qsortx(i,r);
ifj>l then qsortx(l,j);
end;
//==============================================
procedure qsorty(l,r:longint);
var
i,j,k:longint;
t:act;
begin
i:=l;j:=r;
k:=ay[(i+j)shr 1].y;
repeat
whileay[i].y<k do inc(i);
whileay[j].y>k do dec(j);
ifi<=j then
begin
t:=ay[i];ay[i]:=ay[j];ay[j]:=t;
inc(i);dec(j);
end;
untili>j;
ifi<r then qsorty(i,r);
ifj>l then qsorty(l,j);
end;
//===============================================
begin
assign(input,'right.in');reset(input);
assign(output,'right.out');rewrite(output);
readln(n);
fori:=1 to n do
begin
readln(ax[i].x,ax[i].y);
ay[i]:=ax[i];
a[i]:=ax[i];
end;
qsortx(1,n);
qsorty(1,n);
ans:=0;
fori:=1 to n do
begin
l:=1;r:=n;
while l<r do
ifay[(l+r)shr 1].y>=a[i].y then r:=(l+r)shr 1
else l:=(l+r)shr 1+1;
k:=l;
whileay[k].y=ay[l].y do inc(l);
k:=l-k;
l:=1;r:=n;
while l<r do
ifax[(l+r)shr 1].x>=a[i].x then r:=(l+r)shr 1
else l:=(l+r)shr 1+1;
t:=l;
while ax[t].x=ax[l].x do inc(l);
t:=l-t;
ans:=ans+(k-1)*(t-1);
end;
writeln(ans);
close(input);close(output);
end.