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. 5.用JQuery实现选中select里面的option显示对应的div

    用JQuery实现选中select里面的option显示对应的div HTML: <select name=""  onchange="select(this)&q ...

  2. node.js初识12

    1.express框架属于后端的框架 cnpm install --save express --save的作用是将下载的保存在package.json中 你可以点击http://www.expres ...

  3. G 面经 && Leetcode: Longest Repeating Character Replacement

    Given a string that consists of only uppercase English letters, you can replace any letter in the st ...

  4. 第四章 CSS3概述

    1.CSS3新增常用选择器(1)结构性伪类选择器:root 文档根元素 :nth-child(n) 第N个子元素"first-child 第一个元素 :kast-child 最后一个子元素 ...

  5. RabbitMQ理论

    RabbitMQ理论   消息 = 有效载荷(数据) + 标签(包含载荷和收件人的信息)   信道:你的应用于RabbitMQ代理服务器之间的TCP连接(有唯一的ID),信道主要解决了每一个线程单独T ...

  6. Debug常用命令

    R命令 查看.修改CPU中寄存器的值 -r ;查看寄存器的值 -r cs ;修改cs寄存器的值 D命令 查看内存中的内容 ;d 段地址:偏移地址 -d 1000:01 ;查看内存100001处的内容 ...

  7. Vue系列之 => 使用第三方animated.css动画

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  8. Mybatis Generator 使用com.mysql.cj.jdbc.Driver遇到的问题

    Mybatis Generator 使用com.mysql.cj.jdbc.Driver遇到的问题 今天闲来无事,准备搭一套SSM的环境,当然所有的jar包都用最新的. Mybatis使用3.4.6, ...

  9. Another Meaning (KMP + DP)

    先用KMP重叠匹配求出各个匹配成功的尾串位置.然后利用DP去求,那转移方程应该是等于 上一个状态 (无法匹配新尾巴) 上一个状态 + 以本次匹配起点为结尾的状态(就是说有了新的位置) + 1 (单单一 ...

  10. Spark学习之路 (三)Spark之RDD

    一.RDD的概述 1.1 什么是RDD? RDD(Resilient Distributed Dataset)叫做弹性分布式数据集,是Spark中最基本的数据抽象,它代表一个不可变.可分区.里面的元素 ...