SRM 619
。。
。
能够记录一下临近的元素的相互关系(记录临近的4个B串元素的相互关系就可以)
dp[i+1][newj][newk]+=dp[i][j][k]*add。假设b[i+2]和a[i]都是选择b[i-2]~b[i+1]中出现过的数。add就是1,否则add是选择的方案数。
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstring>
using namespace std;
class SimilarSequencesAnother {
public:
int getCount(int, int);
};
long long pmod = 1000000009;
long long dp[105][1 << 9][100];
int Hash[5][5][5][5];
int rHash[10005][4];
int ed = 0;
int add(int a[]) {
if (Hash[a[0]][a[1]][a[2]][a[3]] != -1)
return Hash[a[0]][a[1]][a[2]][a[3]];
Hash[a[0]][a[1]][a[2]][a[3]] = ed;
for (int i = 0; i < 4; ++i)
rHash[ed][i] = a[i];
ed++;
return ed - 1;
}
void get(int id, int a[]) {
for (int i = 0; i < 4; ++i)
a[i] = rHash[id][i];
}
int tmp[5], tt[4], flag[10];
int SimilarSequencesAnother::getCount(int N, int bound) {
int i, j, k, r;
int jj, kk, p;
long long cost1, cost2;
long long m = bound;
memset(dp, 0, sizeof(dp));
memset(Hash, -1, sizeof(Hash));
ed = 0;
tt[0] = 0;tt[1] = 0;tt[2] = 0;tt[3] = 0;
add(tt);
dp[0][1][0] = m;
if (m >= 2) {
tt[0] = 0;tt[1] = 0;tt[2] = 0;tt[3] = 1;
add(tt);
dp[0][1][1] = m * (m - 1) % pmod;
}
for (i = 0; i < N; ++i) {
for (j = 0; j < (1 << 9); ++j) {
for (k = 0; k < ed; ++k) {
if (dp[i][j][k] == 0)
continue;
get(k, tmp);
int pn = max(tmp[0], max(tmp[1], max(tmp[2], tmp[3]))) + 1;
for (tmp[4] = 0; tmp[4] <= pn; ++tmp[4]) {
//把tmp[1]->tmp[4]拷贝到tt,并变成最小表达
memset(flag, -1, sizeof(flag));
int ttn = 0;
for (r = 0; r < 4; ++r) {
if (flag[tmp[r + 1]] == -1) {
flag[tmp[r + 1]] = ttn++;
}
tt[r] = flag[tmp[r + 1]];
}
////////////////////////////////////////
if (tmp[4] == pn)
cost1 = m - pn;
else
cost1 = 1;
if (cost1 <= 0)
continue;
kk = add(tt);
for (p = 0; p <= max(tmp[4] + 1, pn); p++) {//枚举A串当前字符
if (p == max(tmp[4] + 1, pn))
cost2 = m - max(tmp[4] + 1, pn);
else
cost2 = 1;
if (cost2 <= 0)
continue;
jj = 0;
for (r = 0; r < 9; ++r) {
if (j & (1 << r)) {
for (int movea = 0; movea < 2; ++movea)
for (int moveb = 0; moveb < 3; ++moveb) {
int xx = r % 3 + movea;
int yy = r / 3 + moveb;
if (xx > 2 || yy > 2)
continue;
if (movea) {
jj |= (1 << (yy * 3 + xx));
continue;
}
if (p == tmp[2 - xx + yy])
jj |= (1 << (yy * 3 + xx));
}
}
}
dp[i + 1][jj][kk] += dp[i][j][k] * cost1 % pmod * cost2
% pmod;
dp[i + 1][jj][kk] %= pmod;
}
}
}
}
}
long long ans = 0;
for (j = 1; j < (1 << 9); ++j) {
for (k = 0; k < ed; ++k) {
if (rHash[k][2] == 0 && rHash[k][3] == 0) {
ans += dp[N][j][k];
ans %= pmod;
}
}
}
return ans;
}
SRM 619的更多相关文章
- topcoder SRM 619 DIV2 GoodCompanyDivTwo
注意题目给的最后一句话,如果部门任何employee都做不同类型的工作,则这个部门是一个diverse,题目是计算department的diverse数 读起来感觉有点别扭,英语没学好的原因 int ...
- Topcoder SRM 619 DIv2 500 --又是耻辱的一题
这题明明是一个简单的类似约瑟夫环的问题,但是由于细节问题迟迟不能得到正确结果,结果比赛完几分钟才改对..耻辱. 代码: #include <iostream> #include <c ...
- TC250专场
SRM 623 DIV2 1000pt 题意:给出一个最多50*50的矩阵,每个单元可能为'.'.'P'.'A','.'代表空地,你每次操作可以把一个P或者A拿到空地上,求一个最大的含有相同字符的矩形 ...
- Juniper SSG5 PPTP VPN 619错误解决
公司分部的客户端需要使用PPTP VPN连接总部,将网关更换为Juniper SSG5后,客户端出现了每几个小时自动断开的现象,错误619. 解决:Security —— ALG —— 开启PPTP协 ...
- 记第一次TopCoder, 练习SRM 583 div2 250
今天第一次做topcoder,没有比赛,所以找的最新一期的SRM练习,做了第一道题. 题目大意是说 给一个数字字符串,任意交换两位,使数字变为最小,不能有前导0. 看到题目以后,先想到的找规律,发现要 ...
- SRM 513 2 1000CutTheNumbers(状态压缩)
SRM 513 2 1000CutTheNumbers Problem Statement Manao has a board filled with digits represented as St ...
- SRM 510 2 250TheAlmostLuckyNumbersDivTwo(数位dp)
SRM 510 2 250TheAlmostLuckyNumbersDivTwo Problem Statement John and Brus believe that the digits 4 a ...
- SRM 657 DIV2
-------一直想打SRM,但是感觉Topcoder用起来太麻烦了.题目还是英文,不过没什么事干还是来打一打好了.但是刚注册的号只能打DIV2,反正我这么弱也只适合DIV2了.. T1: 题目大意: ...
- SRM DIV1 500pt DP
SRM 501 DIV1 500pt SRM 502 DIV1 500pt SRM 508 DIV1 500pt SRM 509 DIV1 500pt SRM 511 DIV1 500pt SRM 5 ...
随机推荐
- 解决“”父级标签和子标签边框重叠,设置子标签的margin父标签会跟着移动“”的方法
1.可以给父标签一个padding,然后给一个很小的值,虽然不影响整体但是不建议使用 2.给父标签一个"over:hidden"的样式,推荐使用
- print($arr,true)的参数true表示将$arr的值返会,而不是打印
之前通过error_log()来调试php, 发现收到的json字符前边总是有一个1,一直以为是哪里直接出现了print.print_r.echo.var_dump(), 后来发现原来是某处用了形如e ...
- openldap slapd.conf参数
已安装系统的 /etc/openldap/slapd.conf 中包含 LDAP 服务器的完整配置文件.在此简述了其中的各个项并说明了必要的调整.以符号 (#) 为前缀的项处于非活动状态.必须取消这个 ...
- Win8交互UX——笔交互
针对触摸输入优化 Window 应用商店应用设计,并在默认情况下获得基本的笔支持. 本主题介绍笔交互的设计注意事项.有关实现笔交互的信息,请参阅响应笔和触笔交互. 笔交互 通过使用笔创建手写便笺.绘图 ...
- WP8.1学习系列(第三章)——磁贴和锁屏通知
一.创建默认磁贴 创建默认磁贴,不需要任何代码只有制作几张图片就可以了. 1.创建工程之后,在工程目录找到package.appxmanifest,打开它. 2.在应用程序栏,通知选项,选择徽章和图块 ...
- java学习之导出Excel
1. 输出表格 poi输出excel最基本是输出table表格,下面是输出区域.总销售额(万元).总利润(万元)简单的表格,创建HSSFWorkbook 对象,用于将excel输出到输出流中 HSSF ...
- sonarqube插件开发(三) 调试插件
环境 windows + eclipse +sonarqube server 5.6.4 准备 新建一个maven项目,其中加入了一些插件所用的jar <project xmlns=" ...
- 【读书笔记】setsockopt
setsockopt 设置套接口的选项. #include <sys/types.h> #include <sys/socket.h> int setsockopt(int ...
- 【BZOJ5090】组题 分数规划
[BZOJ5090]组题 Description 著名出题人小Q的备忘录上共有n道可以出的题目,按照顺序依次编号为1到n,其中第i道题目的难度系数被小Q估计为a_i,难度系数越高,题目越难,负数表示这 ...
- html如何让label在div中的垂直方向居中显示?
设置label的行高 line-height 和div的高度一致即可.