problem1 link

直接动态规划即可。

problem2 link

假设有$r$行,$c$列被修改了奇数次,那么一定有$r*W+c*H-2*r*c=S$。可以枚举这样的组合$(r,c)$,然后计算答案。比如对于$r$行来说,首先需要从$H$行中选出$r$行,即$C_{H}^{r}$。然后对于剩下的$Rcount-r$(一定是偶数)次修改。令$t=\frac{Rcount-r}{2}$,那么就是求有多少个$H$元组 $(a_{1},a_{2},..,a_{H})$满足$a_{i} \ge 0$且$\sum_{i=1}^{H}a_{i}=K$,运用隔板法,这个答案为 $C_{K+H-1}^{H-1}$。

problem3 link

首先,枚举初始时Head所在的位置,然后可以计算出哪些位置是可以随便放置的(因为最后会被修改)。最后,对所有的情况进行容斥。

code for problem1

#include <algorithm>
#include <iostream>
#include <string>
#include <unordered_set>
#include <vector> class CuttingBitString {
public:
int getmin(std::string S) {
const int N = static_cast<int>(S.size());
std::unordered_set<std::string> all;
long long current = 1L;
while (true) {
std::string s = GetBinary(current);
if (s.size() > S.size()) {
break;
}
all.insert(s);
current *= 5;
} auto Check = [&](int left, int right) {
return all.find(S.substr(left - 1, right - left + 1)) != all.end();
}; std::vector<int> f(N + 1, -1);
f[0] = 0;
for (int i = 1; i <= N; ++i) {
for (int j = 0; j < i; ++j) {
if (f[j] != -1 && Check(j + 1, i)) {
int t = f[j] + 1;
if (f[i] == -1 || f[i] > t) {
f[i] = t;
}
}
}
}
return f[N];
} private:
std::string GetBinary(long long x) {
std::string s = "";
while (x != 0) {
if (x % 2 == 0) {
s += '0';
} else {
s += '1';
}
x >>= 1;
}
std::reverse(s.begin(), s.end());
return s;
}
};

code for problem2

#include <algorithm>
#include <iostream>
#include <vector> const int MAX_N = 2332;
const int MAX_M = 1555; int binomial[MAX_N + 1][MAX_M + 1]; class XorBoard {
static constexpr int mod = 555555555; public:
int count(int H, int W, int Rcount, int Ccount, int S) {
Initialize(std::max(Rcount, Ccount) / 2 + std::max(H, W), std::max(H, W)); auto Compute = [&](int H, int Rcount, int h) -> long long {
int t = (Rcount - h) >> 1;
return static_cast<long long>(binomial[H][h]) *
static_cast<long long>(binomial[t + H - 1][H - 1]) % mod;
}; int result = 0;
int start_row = Rcount & 1;
int start_col = Ccount & 1;
for (int i = start_row; i <= Rcount && i <= H; i += 2) {
long long part1 = Compute(H, Rcount, i);
for (int j = start_col; j <= Ccount && j <= W; j += 2) {
if (i * W + j * H - i * j * 2 != S) {
continue;
}
long long part2 = Compute(W, Ccount, j);
result += static_cast<int>(part1 * part2 % mod);
if (result >= mod) {
result -= mod;
}
}
}
return result;
} private:
void Initialize(int max_n, int max_m) {
binomial[0][0] = 1;
for (int i = 1; i <= max_n; ++i) {
binomial[i][0] = 1;
binomial[i][1] = i;
for (int j = 2; j <= max_m; ++j) {
binomial[i][j] = binomial[i - 1][j - 1] + binomial[i - 1][j];
if (binomial[i][j] >= mod) {
binomial[i][j] -= mod;
}
}
}
}
};

code for problem3

#include <iostream>
#include <string>
#include <unordered_set>
#include <vector> class MapGuessing {
public:
long long countPatterns(std::string goal, std::vector<std::string> code) {
std::string cmd = "";
for (auto &e : code) {
cmd += e;
}
std::unordered_set<long long> all_states;
const int N = static_cast<int>(goal.size());
for (int i = 0; i < N; ++i) {
std::vector<int> types(N, -1);
int head = i;
long long state = 0;
bool tag = true;
for (size_t j = 0; j < cmd.size(); ++j) {
if (cmd[j] == '<') {
--head;
} else if (cmd[j] == '>') {
++head;
} else if (cmd[j] == '0') {
types[head] = 0;
} else {
types[head] = 1;
}
if (head < 0 || head >= N) {
tag = false;
break;
}
bool ok = true;
for (int j = 0; j < N && ok; ++j) {
if (types[j] != -1 && types[j] + '0' != goal[j]) {
ok = false;
}
}
if (ok) {
for (int j = 0; j < N && ok; ++j) {
if (types[j] != -1) {
state |= 1LL << j;
}
}
}
}
if (tag) {
all_states.insert(state);
}
}
std::vector<long long> all;
for (auto e : all_states) {
all.push_back(e);
}
return Dfs(all, 0, (1LL << N) - 1, 0);
} private:
long long Dfs(const std::vector<long long> &all_states, size_t depth,
long long current_state, int sgn) {
if (depth == all_states.size()) {
return sgn * Count(current_state);
}
if (current_state == 0) {
return 0;
}
return Dfs(all_states, depth + 1, current_state, sgn) +
Dfs(all_states, depth + 1, current_state & all_states[depth],
sgn <= 0 ? 1 : -1);
} long long Count(long long s) {
int t = 0;
while (s != 0) {
t += s & 1;
s >>= 1;
}
return 1LL << t;
}
};

topcoder srm 555 div1的更多相关文章

  1. Topcoder SRM 643 Div1 250<peter_pan>

    Topcoder SRM 643 Div1 250 Problem 给一个整数N,再给一个vector<long long>v; N可以表示成若干个素数的乘积,N=p0*p1*p2*... ...

  2. Topcoder Srm 726 Div1 Hard

    Topcoder Srm 726 Div1 Hard 解题思路: 问题可以看做一个二分图,左边一个点向右边一段区间连边,匹配了左边一个点就能获得对应的权值,最大化所得到的权值的和. 然后可以证明一个结 ...

  3. topcoder srm 714 div1

    problem1 link 倒着想.每次添加一个右括号再添加一个左括号,直到还原.那么每次的右括号的选择范围为当前左括号后面的右括号减去后面已经使用的右括号. problem2 link 令$h(x) ...

  4. topcoder srm 703 div1 -3

    1.给出一个包含$n$个元素的数组$x$,构造出一个有向无环图满足从节点$i$出发可以访问到的节点数为$x_{i}$. 思路:按照$x$从小到大排序.然后从前向后处理,当前节点依次与前面已经处理的节点 ...

  5. topcoder srm 738 div1 FindThePerfectTriangle(枚举)

    Problem Statement      You are given the ints perimeter and area. Your task is to find a triangle wi ...

  6. Topcoder SRM 602 div1题解

    打卡- Easy(250pts): 题目大意:rating2200及以上和2200以下的颜色是不一样的(我就是属于那个颜色比较菜的),有个人初始rating为X,然后每一场比赛他的rating如果增加 ...

  7. Topcoder SRM 627 div1 HappyLettersDiv1 : 字符串

    Problem Statement      The Happy Letter game is played as follows: At the beginning, several players ...

  8. Topcoder SRM 584 DIV1 600

    思路太繁琐了 ,实在不想解释了 代码: #include<iostream> #include<cstdio> #include<string> #include& ...

  9. TopCoder SRM 605 DIV1

    604的题解还没有写出来呢.先上605的. 代码去practice房间找. 说思路. A: 贪心,对于每个类型的正值求和,如果没有正值就取最大值,按着求出的值排序,枚举选多少个类型. B: 很明显是d ...

随机推荐

  1. 例子:动能并不是特别强(2-3)后,下M5的同时,也是恢复期到期的前一天

    动能并不是特别强(2-3)后,下M5的同时,但是恢复期到期 EG.002195 2017/06/23-->2017/06/29

  2. struts2启动时,出现的com.opensymphony.xwork2.util.finder.ClassFinder - Unable to read class 错误解决办法

    在项目的struts.xml文件中第一行加入<constant name="struts.convention.package.locators" value="c ...

  3. 有关Struts下载文件时报错问题

    在学习文件下载的时候,我也是按照网络课程上面老师的代码一句一句敲得,和老师的一模一样:到最后测试下载的时候出现了如下的错误: 而老师的写的代码可以完美运行,以下是跟着老师敲的代码: package c ...

  4. beego 初体验 - orm

    goland Terminal运行命令: go get github.com/astaxie/beego/orm 安装go mysql驱动: go get github.com/go-sql-driv ...

  5. 第二章 CSS基本属性

    1.CSS:层叠样式表 一个元素允许同时应用多种样式,页面元素最终的样式即为多种样式的叠加效果. 2.CSS样式优先级 行内样式表>内部样式表>外部样式表[就近原则] id选择器>类 ...

  6. Unity shader学习之渐变纹理

    渐变纹理,及使用纹理来存储漫反射光照的结果,这种技术在游戏<军团要塞2>中流行起来,它也是由Valve公司(提出半兰伯特光照技术的公司)提出来的,他们使用这种技术来渲染游戏中具有插画风格的 ...

  7. Python全栈-day4-语法基础2

    一.字符串 1.字符串基础 1)作用:用于描述姓名.性别.地址等信息 2)定义方式:单引号或者双引号以及三引号内添加字符 注:day3中介绍 name = 'zhang' user_name = &q ...

  8. Marlin 擠出頭溫度控制PID值校正

    Marlin 擠出頭溫度控制PID值校正 擠出頭加熱器.溫度感應器安裝好後,先別急著直接指定工作溫度並且加熱.因為控制板上的溫度控制PID參數尚未校正.如果加熱速度過快,有可能會加熱過度並且導致零件燒 ...

  9. Explorer Bo (思维 + 树链剖分)

    题意:求用最少的链覆盖所有的边用最少的总链长度. 思路:为了使得使用的链最少,我们可以知道使用的数量应该是(子叶 + 1)/ 2. 画图可知:当节点下的边数是偶数时,为了将该父节点上的边给连接上,所以 ...

  10. mysql 创建用户,删除用户,增加权限

    1,查询mysql 数据库已经存在的用户: SELECT USER,HOST FROM MYSQL.USER; 2,创建mysql 用户: '; USERNAME:用户名 HOST:主机,PASSWO ...