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. js之静态方法与实例方法

    静态方法是指不需要声明类的实例就可以使用的方法. 实例方法是指必须要先使用"new"关键字声明一个类的实例, 然后才可以通过此实例访问的方法. function staticCla ...

  2. [转]C# 单例模式

    最近在学设计模式,学到创建型模式的时候,碰到单例模式(或叫单件模式),现在整理一下笔记. 在<Design Patterns:Elements of Resuable Object-Orient ...

  3. AOP术语分析

    初看这么多术语,一下子都不好接受,慢慢来,很快就会搞懂. 通知.增强处理(Advice) 就是你想要的功能,也就是上说的安全.事物.日子等.你给先定义好,然后再想用的地方用一下.包含Aspect的一段 ...

  4. bootstrap-table 大量字段整体表单上传之时间处理

    js 中用$('#addUserForm').serialize(),//获取表单中所有数据 传送到前台 (controller) $.ajax({ type : "POST", ...

  5. PHP : 数据库中int类型保存时间并通过年月份时分秒进行显示

    1.表设计: 2.数据库操作页面:将时间戳插入到数据库中 我们到数据库中可以看到: 3.我们将数据进行显示: 页面结果:(二维数组) 4.以为用mysqli_fetch_all得到的是二维数组,那么我 ...

  6. JAVA去掉HTMl以及CSS样式

    封装方法如下 public String delHTMLTag(String htmlStr){ String regEx_style="<style[^>]*?>[\\s ...

  7. 模拟网页的浏览Stack(POJ1028)

    题目链接:http://poj.org/problem?id=1028 注意: 1.用两个栈来模拟,一个用来存可以返回的,一个用来存可以前进的. 2.visit方法,就要将可以前进的栈清空. 3.ba ...

  8. 线程 task pritce

    1.使用task类创建并执行简单任务: 使用task的构造函数来创建 任务,并调用start方法来启动任务,执行异步操作 aitAll用于等待提供的所有 System.Threading.Tasks. ...

  9. EF 连接数据库 Mysql (database first ) 一个表对应一个模型

    准备工作 1.下载vs2015 2.下载mysql2017 3.安装 1.创建数据库 2. 将数据库映射成模型 3创建aspx 文件. 写下窗体内容的代码 hello_worldEntities en ...

  10. IntelliJ IDEA / Eclipse 自动生成 Author 注释 签名

    Author 注释 签名如下: /*** @author 稚枭天卓 E-mail:zhxiaotianzhuo@163.com* @version 创建时间:2016-6-20 下午04:58:52* ...