被第一题傻逼题卡了很久……好的我也是个傻逼

倒在了最后一题 本来以为小数据过了就能过大数据 结果下载了大数据 发现怎么输出了好多个零 调代码过程中超时了 结束后重新提交了一下 果然是不通过的



A

题目

Problem

You are a contestant on a popular new game show and are playing for the grand prize!

There are two big buttons, a red one and a black one. You will make a sequence of exactly N button presses.

There are lots of different sequences of presses you could make, but there are Pforbidden prefixes, each of length no greater than N. If you make a sequence of presses which begins with any of the forbidden sequences, you will not win the grand prize. It is fine for your sequence to contain one or more forbidden prefixes as long as they do not appear at the start of your sequence.

winning sequence must consist of exactly N button presses and must not begin with one of the forbidden prefixes. How many different winning sequences are there?

Input

The first line of the input gives the number of test cases, TT test cases follow. Each test case starts with a line containing two integers N and P, as described above. Then, there are P more lines, each of which contains a string of between 1 and N characters, inclusive, describing one of the forbidden sequences of presses. An R represents pressing the red button, whereas a B represents pressing the black button.

Output

For each test case, output one line containing Case #x: y, where x is the test case number (starting from 1) and y is the number of winning sequences, as desribed above.

Limits

1 ≤ T ≤ 100.
1 ≤ P ≤ min(2N, 100).
Each forbidden prefix is between 1 and N characters long, inclusive.
No two forbidden prefixes will be the same.

Small dataset

1 ≤ N ≤ 10.

Large dataset

1 ≤ N ≤ 50.

Sample

Input 
 
Output 
 
4
3 2
BBB
RB
5 1
R
4 3
R
B
RBRB
50 5
BRBRBBBRBRRRBBB
BRBRBRRRBRRRBRB
BBBRBBBRBRRRBBB
BRBRBRRRBRRRB
BRBRBBBRBBBRB
Case #1: 5
Case #2: 16
Case #3: 0
Case #4: 1125556309458944

Note that the last Sample case would not appear in the Small dataset.

In the first case, you must make a sequence of 3 presses. There are 8 possible sequences of three presses, but some of them will cause you to lose the game. They are listed below:

  • RBB. This is forbidden since it starts with the first forbidden sequence (RB).
  • RBR. This is forbidden since it starts with the first forbidden sequence (RB).
  • BBB. This is forbidden since it starts with the second forbidden sequence (BBB).

Thus, there are only 5 winning sequences.

In the second case, you must make a sequence of 5 presses. There is only one forbidden sequence, which is R. This means that the first press must be B, and the next 4 presses can be either button. This gives a total of 16 different button presses.

In the third case, you must make a sequence of 4 presses. There are three forbidden sequences, but since every possible sequence begins with either R (the first forbidden sequence) or B (the second forbidden sequence), there are no winning sequences. So the answer is 0.


题意

   给出一个仅存在R和B的长度为n的字符串,有m个不能出现的前缀,问这样的字符串有多少。

思路

   崔神给我讲的思路是可以用字典树先对m个前缀建树,然后用dfs剪枝 。

   我自己的做法是对前缀暴力找是否存在一个前缀为另一个前缀的前缀(前缀 i 为前缀 j 的前缀)。若存在,则将长度更长的前缀标记,计算时不再计入。

   对于一个前缀 s 而言,剩余长度(n-s.length())无论怎么排列R和B都是不合法的。

   对计入计算的前缀 s[i]  ,累加(2^(n-s[i].length()),最后用2^n减去累加结果。


代码 (大小数据均为同一份代码,只改动了文件关联)

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <string>
#include <cstring>
#include <algorithm> using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int inf=0x3f3f3f3f;
const char ss[]={'B','R'};
int t,n,m,vis[];
string s[]; bool cmp(string s1,string s2){
if(s1.length()<s2.length()) return s1.length()<s2.length();
} ll qpow(ll x,ll k){
ll res=;
while(k>){
if(k%==){
res=res*x;
}
x=x*x;
k>>=;
}
return res;
} int main(){
// freopen("A-large.in","r",stdin);
// freopen("A.out","w",stdout);
scanf("%d",&t);
for(int id=;id<=t;id++){
memset(vis,,sizeof(vis));
scanf("%d%d",&n,&m);
for(int i=;i<=m;i++){
cin>>s[i];
}
sort(s+,s+m+,cmp);
for(int i=;i<=m;i++){
for(int j=i+;j<=m;j++){
if(vis[i]== || vis[j]==) continue;
int flag=;
for(int k=;k<s[i].length();k++){
if(s[i][k]==s[j][k]) flag++;
if(flag==s[i].length()) vis[j]=;
}
}
}
ll ans=qpow(,n);
for(int i=;i<=m;i++){
if(vis[i]==){
ans-=qpow(,n-s[i].length());
}
}
printf("Case #%d: %lld\n",id,ans);
}
return ;
}


B

题目

Problem

Thanh wants to paint a wonderful mural on a wall that is N sections long. Each section of the wall has a beauty score, which indicates how beautiful it will look if it is painted. Unfortunately, the wall is starting to crumble due to a recent flood, so he will need to work fast!

At the beginning of each day, Thanh will paint one of the sections of the wall. On the first day, he is free to paint any section he likes. On each subsequent day, he must paint a new section that is next to a section he has already painted, since he does not want to split up the mural.

At the end of each day, one section of the wall will be destroyed. It is always a section of wall that is adjacent to only one other section and is unpainted (Thanh is using a waterproof paint, so painted sections can't be destroyed).

The total beauty of Thanh's mural will be equal to the sum of the beauty scores of the sections he has painted. Thanh would like to guarantee that, no matter how the wall is destroyed, he can still achieve a total beauty of at least B. What's the maximum value of B for which he can make this guarantee?

Input

The first line of the input gives the number of test cases, TT test cases follow. Each test case starts with a line containing an integer N. Then, another line follows containing a string of N digits from 0 to 9. The i-th digit represents the beauty score of the i-th section of the wall.

Output

For each test case, output one line containing Case #x: y, where x is the test case number (starting from 1) and y is the maximum beauty score that Thanh can guarantee that he can achieve, as described above.

Limits

1 ≤ T ≤ 100.

Small dataset

2 ≤ N ≤ 100.

Large dataset

For exactly 1 case, N = 5 × 106; for the other T - 1 cases, 2 ≤ N ≤ 100.

Sample

Input 
 
Output 
 
4
4
1332
4
9583
3
616
10
1029384756
Case #1: 6
Case #2: 14
Case #3: 7
Case #4: 31

In the first sample case, Thanh can get a total beauty of 6, no matter how the wall is destroyed. On the first day, he can paint either section of wall with beauty score 3. At the end of the day, either the 1st section or the 4th section will be destroyed, but it does not matter which one. On the second day, he can paint the other section with beauty score 3.

In the second sample case, Thanh can get a total beauty of 14, by painting the leftmost section of wall (with beauty score 9). The only section of wall that can be destroyed is the rightmost one, since the leftmost one is painted. On the second day, he can paint the second leftmost section with beauty score 5. Then the last unpainted section of wall on the right is destroyed. Note that on the second day, Thanh cannot choose to paint the third section of wall (with beauty score 8), since it is not adjacent to any other painted sections.

In the third sample case, Thanh can get a total beauty of 7. He begins by painting the section in the middle (with beauty score 1). Whichever section is destroyed at the end of the day, he can paint the remaining wall at the start of the second day.


题意

   有一个由 0~9 的数字组成的数列,第一次可以随便取一个数字,接下来的每一次只能取一个与已取区间相邻的数字。

   每次取出一个数字后,数列两端的两个数之一会随机地变为不可取。问最坏情况下取出数字的最大和是多少。

思路

   首先知道我们一定能取出一个长度为 (n+1)/2的连续区间;
   而且,不管不可取的数字是如何出现在两端的,对于一个长度为 (n+1)/2 的区间,一定存在一种方法把它取到。
   所以 O(n) 找出区间和最大的长度为 (n+1)/2 的连续区间即可。


代码

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <string>
#include <cstring>
#include <algorithm> using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int inf=0x3f3f3f3f;
const int maxn=5e6+;
int t,n;
int a[maxn],sum[maxn];
char s[maxn]; int main(){
// freopen("B-large.in","r",stdin);
// freopen("B.out","w",stdout);
scanf("%d",&t);
for(int id=;id<=t;id++){
memset(sum,,sizeof(sum));
scanf("%d",&n);
scanf("%s",s+);
for(int i=;i<=n;i++){
a[i]=s[i]-'';
}
sum[]=;
for(int i=;i<=n;i++){
sum[i]=sum[i-]+a[i];
}
int m=(n+)/;
int maxx=;
for(int i=m;i<=n;i++){
maxx=max(maxx,sum[i]-sum[i-m]);
}
printf("Case #%d: %d\n",id,maxx);
}
return ;
}


---恢复内容结束---

2018 codejam kickstart H轮的更多相关文章

  1. 【欧拉回路+最小生成树】SD开车@山东2018省队一轮集训day1

    目录 [欧拉回路+最小生成树]SD开车@山东2018省队一轮集训day1 PROBLEM 题目描述 输入 输出 样例输入 样例输出 提示 SOLUTION CODE [欧拉回路+最小生成树]SD开车@ ...

  2. Good Bye 2018 (A~F, H)

    目录 Codeforces 1091 A.New Year and the Christmas Ornament B.New Year and the Treasure Geolocation C.N ...

  3. 2018 江苏省邀请赛 H

    题目链接 https://nanti.jisuanke.com/t/28872 解析 递推 直接套杜教板子 AC代码 #include <cstdio> #include <cstr ...

  4. 2018山东省赛 H Dominoes ( 搜索 )

    题目链接 题意 : 给出一个 n * m 的矩阵,用规格 1 * 2 的多米诺去填充,题目数据保证最后只有一个格子是空白的(即没有被多米诺骨牌覆盖),问你现在通过移动多米诺能够产生多少种不同的状态(空 ...

  5. 2018 ACM-ICPC 宁夏 H.Fight Against Monsters(贪心)

    It is my great honour to introduce myself to you here. My name is Aloysius Benjy Cobweb Dartagnan Eg ...

  6. 2018 ICPC北京 H ac自动机

    n=40的01串,求有多少m=40的01串中包含它,包含的定义是存在子串有至多一个字符不相同 600组n=15的数据 15组n=40的数据,所以我们只能支持n^5的算法. 陷入两个比较有意思的坑: 1 ...

  7. linux常用头文件及说明

    linux常用头文件及说明 1. Linux中一些头文件的作用: <assert.h>:ANSI C.提供断言,assert(表达式)<glib.h>:GCC.GTK,GNOM ...

  8. Linux C 一些函数 所属头文件

    1. Linux中一些头文件的作用:<assert.h>:ANSI C.提供断言,assert(表达式)<glib.h>:GCC.GTK,GNOME的基础库,提供很多有用的函数 ...

  9. Linux中常用头文件的作用--转

    http://blog.sina.com.cn/s/blog_5c93b2ab0100q62k.html 1. Linux中一些头文件的作用: <assert.h>:ANSI C.提供断言 ...

随机推荐

  1. 字符设备驱动(六)按键poll机制

    title: 字符设备驱动(六)按键poll机制 tags: linux date: 2018-11-23 18:57:40 toc: true --- 字符设备驱动(六)按键poll机制 引入 在字 ...

  2. Perl参数

    一.#!/usr/bin/perl -w -w:prints warnings about dubious(可疑的,不确定的) constructs perldoc perlrun#可以查看参数详情 ...

  3. Hadoop生态圈-开启Ambari的Kerberos安全选项

    Hadoop生态圈-开启Ambari的Kerberos安全选项 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 在完成IPA-Server服务的安装之后,我们已经了解了他提供的基础功 ...

  4. 利用 JMetal 实现大规模聚类问题的研究(一)JMetal配置

    研究多目标优化问题,往往需要做实验来对比效果,所以需要很多多目标方面的经典代码,比如NSGA-II, SPEA, MOEA,MOEA/D, 或者PSO等等. 想亲自实现这些代码,非常浪费时间,还有可能 ...

  5. JAVA核心技术I---JAVA基础知识(内部类)

    一:内部类概述 (一)定义 内部类(Inner Class)是定义在其他类中或方法中的类,包含内部类的类通常称作Enclosing Class 内部类的功能通常与包含它的类的功能有紧密的关联 内部类的 ...

  6. Sublime Text 3 Mac常用快捷键与注意事项

    大多数情况下容易忘记的快捷键,在此整理了一下. 编辑快捷键:cmd+L:选择行(重复按下将下一行加入选择):cmd+D:选择词(重复按下时多重选择相同的词进行多重编辑):cmd+shift+D 复制光 ...

  7. Gson入门教程【原】

    gson一个jar包就能纵横天下,不像Json-lib.jar依赖其它jar包. 点击右边图片下载jar包       或以下链接 http://central.maven.org/maven2/co ...

  8. MVC Repository模式

    近来发现很多ASP.NET MVC的例子中都使用了Repository模式,比如Oxite,ScottGu最近发布的免费的ASP.NET MVC教程都使用了该模式.就简单看了下. 在<企业架构模 ...

  9. js工具库

    js-md5:https://www.npmjs.com/package/js-md5

  10. 实惠VPS推荐

    1. Topmain 2. Virmach 3. BanwagonHost  [备用地址1] [备用地址2] 4. HiFormance  (跑路) 5. my.hosteons.com 6. . 以 ...