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 ...
随机推荐
- WinDBG 技巧:列出模块(DLL/EXE)里面所有的符号(symbol)
想对某个函数下断点,但是记不清楚的函数具体的名字,这个时侯可以使用x命令来列举所有的符号. 命令格式为: x [选项] 模块名字!符号匹配表达式 这里的符号匹配表达式类似dos的文件名匹配表达式,可以 ...
- 用layer插件实现tp3.2的分页
主要需要用到 /layer/layer.js 这个, 现在一个tp前端视图/article/index.html <!DOCTYPE html> <html lang=" ...
- sqlserver添加查询 表、字段注释(转)
环境:xp sp3,sql server2008 .sqlserver用语句给表注释 EXECUTE sp_addextendedproperty N'MS_Description', N'表注释', ...
- 【2014年12月6日】HR交流会
今天的交流会感觉还是不错,体会到了一些东西,把它记下来. 想到什么写什么,可能没什么条理. 1.先选行业,再选职业,再选公司 根据自己的兴趣以及个人特长,能力等方面,需要定一个大概的方向,然后根据方向 ...
- 【linux系列】压缩和解压缩tar
tar -c: 建立压缩档案-x:解压-t:查看内容-r:向压缩归档文件末尾追加文件-u:更新原压缩包中的文件 这五个是独立的命令,压缩解压都要用到其中一个,可以和别的命令连用但只能用其中一个.下面的 ...
- Android 请求运行时权限
写文件到sd卡中,会报权限问题,需要动态申请申请运行时权限 1. MainActivity.java public class MainActivity extends Activity { priv ...
- 使用 Gogs 搭建自己的 Git 服务器
安装过程分为这些步骤: 新建用户: 下载源码编译 / 下载预编译二进制打包: 运行安装: 配置调整: 配置 nginx 反向代理: 保持服务运行: 注意,这里默认你已经安装好了 MySQL 服务器和 ...
- DragonBones龙骨发布后在Egret中的位置
DragonBones发布后的动画,加载到Egret中场景中,原点的位置在哪呢? DragonBones中的图片位置 导出 加载到Egret中.可见DragonBones中的图片位置原点左下方(0,0 ...
- Egret第三方库的制作和使用(模块化 第三方库)
一.第三方库的制作 官方教程:第三方库的使用方法 水友帖子:新版本第三方库制作细节5.1.x 首先在任意需要创建第三方库的地方,右键,选择"在此处打开命令窗口" 输入egret c ...
- 【C#】简单计算器源代码
form1.cs using System; using System.Collections.Generic; using System.ComponentModel; using System.D ...