A  CodeChef - KSPHERES

中文题意  Mandarin Chinese

Eugene has a sequence of upper hemispheres and another of lower hemispheres. The first set consists of N upper hemispheres indexed 1 to N and the second has M lower hemispheres indexed 1 to M. The hemispheres in any sequence can have different radii.

He is now set out on building spheres using them. To build a sphere of radius R, he must take one upper half of the radius R and one lower half of the radius R. Also, he can put a sphere into a bigger one and create a sequence of nested concentric spheres. But he can't put two or more spheres directly into another one.

Examples:


If there is a sequence of (D+1) nested spheres, we can call this sequence as a D-sequence.


Eugene has to find out how many different X-sequence are possible (1 <= X <= C). An X sequence is different from another if the index of any of the hemisphere used in one X-sequence is different from the other. Eugene doesn't know how to do it, so Chef agreed to help him. Of course, Chef is too busy now and he asks you to help him.

Input

The first line contains a three integers: N denoting the number of upper sphere halves, M denoting the number of lower sphere halves and C.

The second line contains N space-separated integers U1U2, ..., UN denoting the radii of upper hemispheres.

The third line contains M space-separated integers L1L2, ..., LM denoting the radii of lower hemispheres.

Output

Output a single line containing C space-separated integers D1D2, ..., DC, where Diis the number of ways there are to build i-sequence in modulo 109+7.

Constraints

  • 1 ≤ N ≤ 105
  • 1 ≤ M ≤ 105
  • 1 ≤ C ≤ 103
  • 1 ≤ Ui ≤ C
  • 1 ≤ Li ≤ C

Subtasks

  • Subtask 1: 1 ≤ N, M, C ≤ 10 - 15 points
  • Subtask 2: 1 ≤ N, M, C ≤ 100 - 25 points
  • Subtask 3: Original constraints - 60 points

Example

Input:
3 4 3
1 2 3
1 1 3 2
Output:
5 2 0

Explanation

We can build spheres with such radii:

R=1 and there are 2 ways to do it. (We can choose any of 2 lower hemispheres with R=1)

R=2 and there is 1 way to do it.

R=3 and there is 1 way to do it.

We can build these 1-sequences:

1->2 and there are 2 ways to do it. ( sphere with radius 1 is inside sphere with radius 2, we can choose any of 2 ways of building sphere with radius 1)

1->3 and there are 2 ways to do it.

2->3 and there is 1 way to do it.

2 + 2 + 1 = 5

We can build these 2-sequences:

1->2->3 and there are 2 ways to do it.

We can't build 3-sequences, because we don't have 4 spheres of different radii.

Mandarin Chinese

题解:当时这题考试来着,想了10分钟,手推了一下,发现对于每个i的答案就是这c个数取i个的组合,然后我就暴力求每个数的组合了。。。居然还打了半小时==,以为有5s时限能卡过,但没想到只有15分。

纪念一下。。

 var
n,m,c,i,j,k,tot,l:longint;
ans:int64;
vis:array[..]of boolean;
a,b,t,rt,d,sum,num:array[..]of longint;
procedure dfs(s:longint);
var i,su:longint;
begin
if s=k+ then
begin
su:=;
for i:= to k do su:=su*d[num[i]] mod ;
// for i:= to k do write(num[i],' ');
// writeln;
ans:=(ans+su)mod ;
exit;
end else
for i:=num[s-]+ to c do
begin
num[s]:=i;
vis[i]:=true;
dfs(s+);
vis[i]:=false;
end;
end;
begin
readln(n,m,c);
for i:= to n do begin read(a[i]); inc(t[a[i]]);end;
readln;
for i:= to m do begin read(b[i]); inc(rt[b[i]]);end;
for i:= to c do
begin
d[i]:=(t[i]*rt[i]) mod ;
end;
// for i:= to c do writeln(d[i]);
for i:= to c do
begin
k:=i+;
if k>c then begin write(,' ');continue; end;
ans:=;
for l:= to do num[i]:=;
for l:= to do vis[i]:=false;
dfs(); write(ans mod ,' ');
end; end.

考完之后询问大佬,发现可以dp? 类似于递推,再回去看我的那些组合,后面的组合包含前面的,前面是后面的子问题,用dp思想,f[i][j]表示套i个圆,当前最大的圆的半径是j的方案数。

(其实dp方程表示出来的东西要能表示整个题目的问题和答案)递推方程就是f[i,j]=f[i,j-1]+f[i-1,j-1]*d[i]  f[i,j-1]是继承前面一个圈的,f[i-1,j-1]是当前这个圈的方案数。

 var
n,m,c,i,j,k,tot,l,modd:longint;
ans:int64;
f:array[..,..]of int64;
vis:array[..]of boolean;
a,b,t,rt,d,sum,num:array[..]of longint;
begin
modd:=;
readln(n,m,c);
for i:= to n do begin read(a[i]); inc(t[a[i]]);end;
readln;
for i:= to m do begin read(b[i]); inc(rt[b[i]]);end;
for i:= to c do
begin
d[i]:=(t[i]*rt[i]) mod ;
end;
// for i:= to c do writeln(d[i]);
for i:= to c do f[][i]:=f[,i-]+d[i];
for i:= to c- do
for j:= to c do
begin
f[i,j]:=(f[i,j-]+(f[i-,j-]*d[j]) mod modd)mod modd;
end;
for i:= to c do write(f[i,c],' ');
end.

明显短了不少==

B - Sereja and Commands

中文题意 mandarin chinese

题解:因为每次都是加1,而且操作如此多次,暴力直接算会超时,操作多次用递归计算又很麻烦,所以。。想到差分。比如你要在x~y区间上加1,操作就是在a[x]位置+1,在a[y-1]的位置-1

最后从1~n扫一遍,a[i]=a[i]+a[i-1]就行了。另外在操作2的时候,你需要从后往前搜(后面不影响前面),也要用差分来做,不然只有50分,所以这个题目,需要用到两个差分来做,

最最后,还要注意负数取mod, (x mod INF+INF)mod INF    (INF为模数)

 var
a,q,x,y,id,b:array[-..]of int64;
t,n,m:int64;
i,j,l:longint;
modd:longint;
begin
readln(t);
modd:=+;
for l:= to t do
begin
//fillchar(q,sizeof(q),);
// fillchar(x,sizeof(x),);
// fillchar(y,sizeof(y),);
fillchar(b,sizeof(b),);
fillchar(a,sizeof(a),);
readln(n,m);
for i:= to m do
begin
readln(q[i],x[i],y[i]);
inc(id[i]);
end;
b[m]:=;
for i:=m downto do
begin
b[i]:=(b[i]+b[i+])mod modd;
if q[i]= then
begin
// for j:=x[i] to y[i] do id[j]:=((id[j]+id[i])mod modd+modd)mod modd;
b[y[i]]:=(b[y[i]]+b[i])mod modd;
b[x[i]-]:=((b[x[i]-]-b[i])mod modd+modd)mod modd;
// id[i]:=;
end;
end;
for i:= to m do
if q[i]= then
begin
a[x[i]]:=((a[x[i]]+b[i])mod modd+modd)mod modd;
a[y[i]+]:=((a[y[i]+]-b[i])mod modd+modd)mod modd;
end;
for i:= to n do
begin
a[i]:=((a[i-]+a[i])mod modd+modd)mod modd;
write(a[i],' ');
end;
writeln;
end;
end.

C - Blocked websites

中文题意  mandarin chinese

题意:给你若干个英文单词,前带+号的要保留,前带-号的要舍去,舍去的方法是用 前缀过滤器,就是以此为前缀的单词会被舍去。求出最少需要的个数和输出该前缀。如果做不到就输出-1.

题解:考试的时候当然想不出了。考后问大佬,可以用字典树做?那就来普及一下字典树吧。据我的理解,就是把一个字符串存入树中,每个节点是一个字符(char),插入字符串时,如果当前字符树中有,树中该字符num[ ]++,然后遍历下去,若没有,就新开一个节点记录,最后应该是一个森林。

在此题中,字典树建好后,你需要再开两个数组,ban 和 admit 。分别记录该节点字符舍去和保留的数目。

最后从根节点 dfs一遍,若遇到admit[now]=0 时,则说明该节点下去没有需保留的单词了,那就返回该节点被ban的字符个数和字符串(前缀),还有做不到的

情况是返回ban的字符个数小于总的要被ban个数,则输出-1.(情理之中,不需要想太多)

 var
n,m,i,ssum,sum,tot,bannum,c,k:longint;
s:ansistring;
ans:array[..]of ansistring;
tree:array[..,..]of longint;
adm,ban:array[..]of longint;
7 procedure insert(s1:ansistring;c:longint);// 字典树建树 模板
8 var len,now,val,i:longint;
9 begin
10 now:=0;val:=0;len:=length(s1);
11 for i:=1 to len do
12 begin
13 val:=ord(s1[i])-ord('a');
14
15 if tree[now,val]=0 then
16 begin
17 inc(tot);
18 tree[now,val]:=tot;
19 end;
20 now:=tree[now,val];// 注意,now<>tot 如果字典树中有该字符,就不需要++tot了,直接指为它就好
21 // inc(num[now]);
22
23 if c=1 then inc(adm[now]) else inc(ban[now]);
24
25 end;
// endd[now]:=true;
26 end;
procedure dfs(u:longint;nows:ansistring);
var i:longint;
begin
// writeln(nows);
// writeln(u);
if adm[u]= then
begin
inc(sum);
ans[sum]:=nows;
ssum:=ssum+ban[u];
exit;
end;
if ban[u]= then exit;
for i:= to do // 0 所表示的字符为'a' ,从'a'~'z'
begin
if tree[u,i]<> then dfs(tree[u,i],nows+chr(i+ord('a'))); end;
end; begin
readln(n);
for i:= to n do
begin
readln(s);
if s[]='+' then c:= else begin c:=; inc(bannum); end;
// writeln(copy(s,,length(s)-));
insert(copy(s,,length(s)-),c);
end;
adm[]:=-; ban[]:=-;//初始化,根节点不参与
dfs(,'');
// writeln(adm[]);
// writeln(ans[]);
if ssum<bannum then writeln(-) else
begin
writeln(sum);
for i:= to sum do writeln(ans[i]);
end;
end.

contest0 from codechef的更多相关文章

  1. 【BZOJ-3514】Codechef MARCH14 GERALD07加强版 LinkCutTree + 主席树

    3514: Codechef MARCH14 GERALD07加强版 Time Limit: 60 Sec  Memory Limit: 256 MBSubmit: 1288  Solved: 490 ...

  2. 【BZOJ4260】 Codechef REBXOR 可持久化Trie

    看到异或就去想前缀和(⊙o⊙) 这个就是正反做一遍最大异或和更新答案 最大异或就是很经典的可持久化Trie,从高到低贪心 WA: val&(1<<(base-1))得到的并不直接是 ...

  3. codechef 两题

    前面做了这场比赛,感觉题目不错,放上来. A题目:对于数组A[],求A[U]&A[V]的最大值,因为数据弱,很多人直接排序再俩俩比较就过了. 其实这道题类似百度之星资格赛第三题XOR SUM, ...

  4. codechef January Challenge 2014 Sereja and Graph

    题目链接:http://www.codechef.com/JAN14/problems/SEAGRP [题意] 给n个点,m条边的无向图,判断是否有一种删边方案使得每个点的度恰好为1. [分析] 从结 ...

  5. BZOJ3509: [CodeChef] COUNTARI

    3509: [CodeChef] COUNTARI Time Limit: 40 Sec  Memory Limit: 128 MBSubmit: 339  Solved: 85[Submit][St ...

  6. CodeChef CBAL

    题面: https://www.codechef.com/problems/CBAL 题解: 可以发现,我们关心的仅仅是每个字符出现次数的奇偶性,而且字符集大小仅有 26, 所以我们状态压缩,记 a[ ...

  7. CodeChef FNCS

    题面:https://www.codechef.com/problems/FNCS 题解: 我们考虑对 n 个函数进行分块,设块的大小为S. 每个块内我们维护当前其所有函数值的和,以及数组中每个元素对 ...

  8. codechef Prime Distance On Tree(树分治+FFT)

    题目链接:http://www.codechef.com/problems/PRIMEDST/ 题意:给出一棵树,边长度都是1.每次任意取出两个点(u,v),他们之间的长度为素数的概率为多大? 树分治 ...

  9. BZOJ 3221: [Codechef FEB13] Obserbing the tree树上询问( 可持久化线段树 + 树链剖分 )

    树链剖分+可持久化线段树....这个一眼可以看出来, 因为可持久化所以写了标记永久化(否则就是区间修改的线段树的持久化..不会), 结果就写挂了, T得飞起...和管理员拿数据调后才发现= = 做法: ...

随机推荐

  1. vue安装--使用node

    总结: # 全局安装 vue-cli $ npm install --global vue-cli # 创建一个基于 webpack 模板的新项目 $ vue init webpack my-proj ...

  2. Android's Media

    MediaService.Main #include <sys/types.h> #include <unistd.h> #include <grp.h> #inc ...

  3. Python开发环境Wing IDE之Search in Files工具详解

    Search in Files工具是Wing IDE中最强大的搜索选项.它支持磁盘.项目,打开编辑器,或其它文件集的多文件批量搜索.它还可以使用通配符搜索,并可以做基于正则表达式的搜索/替换. 建议用 ...

  4. Struts2_HelloWorld_6

    为 eclipse 在编写 xml配置文件时提供提示,需要加上dtd或xls的标签定义文件的路径,具体操作: 1.Window——Preferences——XML Catalog 2.添加 dtd 文 ...

  5. Quartz .Net(定时框架):

    Quartz .Net(定时框架): 基本说明: 说明:Quartz .Net 是一个从 Java 版的 Quartz 移植过来定时任务框架,可以实现异常灵活的定 时任务 用法: 安装 Quartz ...

  6. python JSON性能测试与simplejson对比

    简单测试了一下,如果用JSON,也就是python2.6以上自带的json处理库,效率还算可以: 1K的数据,2.9GHz的CPU,单核下每秒能dump:36898次.大约是pyamf的5倍.但数据量 ...

  7. S7-1500 读取V90/S120/S210/G120的常用驱动参数

    S7-1500 读取V90/S120的常用驱动参数 此程序已更新,可以下载例子程序 https://files.cnblogs.com/files/lion-zheng/PLC_async_drive ...

  8. kinectV2平面检测

    最近做一个关于kinect的东西,主要是在RGB图上提取指定的平面.对于kinect也是刚刚接触不是很熟悉,捣鼓了两天做了很粗糙的东西,但是也学到了一些东西,所以记录一下. 思路大概就是: 在RGB中 ...

  9. MySQL入门很简单: 1 数据库概述

    1. 数据库概述 1.1 数据存储方式: 1)人工管理阶段 2)文件系统阶段: 文件系统通过文件的存储路径和文件名称访问文件中的数据 3)数据库系统阶段:Oracle, SQL Server, MyS ...

  10. Sublime插件支持Sass编译和Babel解析ES6 & .sublime-build文件初探(转载自imwtr)

    原文请看:http://www.cnblogs.com/imwtr/p/6010550.html   用Sublime Text蛮久了,配置配来配去的,每次换电脑都得重头再配过,奈何人老了脑子不中用了 ...