2019牛客多校 Round2
Solved:2
Rank:136
A Eddy Walker
题意:T个场景 每个场景是一个长度为n的环 从0开始 每次要么向前走要么向后走 求恰好第一次到m点且其他点都到过的概率
每次的答案是前缀概率积
题解:m=0的时候 只有n=1的时候是1 否则是0 然后感性的理解到其他n-1点的概率是一样的 所以每个点的概率是1/(n-1)
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod = 1e9 + 7; ll pow_mod(ll x, ll y) {
ll res = 1;
while(y) {
if(y & 1) res = res * x % mod;
x = x * x % mod;
y >>= 1;
}
return res;
} int main() {
ll ans = 1;
int T;
scanf("%d", &T);
while(T--) {
ll n, m;
scanf("%lld%lld", &n, &m);
if(n == 1 && m == 0) {
printf("%lld\n", ans);
continue;
}
if(m == 0) ans = 0;
else ans = ans * pow_mod(n - 1, mod - 2) % mod;
printf("%lld\n", ans);
}
return 0;
}
A Eddy Walker
D Kth Minimum Clique
题意:100个点的图 输出点权第k小的团
题解:考虑把点一个一个插入进去 用优先队列维护团的大小
每次取出最小的团 然后判断一下可以把哪个点放进来继续是团 用bitset维护
#include <bits/stdc++.h>
using namespace std;
typedef long long ll; int n, k, cnt;
int val[105];
char tu[105][105]; struct node {
int pos;
ll sum;
bitset<105> bt; friend bool operator < (node A, node B) {
return A.sum > B.sum;
}
}; bitset<105> btt[105];
int main() {
cnt = 0;
scanf("%d%d", &n, &k); for(int i = 1; i <= n; i++) scanf("%d", &val[i]);
for(int i = 1; i <= n; i++) {
scanf("%s", tu[i] + 1);
for(int j = 1; j <= n; j++)
if(tu[i][j] == '1') btt[i][j] = 1;
} if(k == 1) {
puts("0");
return 0;
}
k--; priority_queue<node> que;
for(int i = 1; i <= n; i++) que.push((node){i, 1LL * val[i], btt[i]}); while(!que.empty()) {
node t = que.top();
que.pop();
k--;
if(k == 0) {
printf("%lld\n", t.sum);
return 0;
} for(int i = t.pos + 1; i <= n; i++)
if(t.bt[i]) que.push((node){i, t.sum + 1LL * val[i], t.bt & btt[i]});
}
puts("-1");
return 0;
}
D Kth Minimum Clique
E MASE
题意:给一个N x M的01矩阵(M <= 10) 1表示墙 每个点可以往左右下走
一个修改操作 把之前矩阵中某个位置的数取反
一个查询操作 查询从第一行的一个位置走到第n行一个位置的方案数
题解:做的第一道动态DP的题 由于一些奇特的性质
DP的转移可以用矩阵表示 矩阵乘法有结合率 线段树可以维护矩阵的区间积
然后就这样了....
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod = 1e9 + 7; int n, m, t;
char s[100005][12];
struct martix {
ll c[10][10];
}sum[400005]; martix mul(martix x, martix y) {
martix res;
for(int i = 0; i < m; i++)
for(int j = 0; j < m; j++) res.c[i][j] = 0; for(int i = 0; i < m; i++)
for(int k = 0; k < m; k++)
for(int j = 0; j < m; j++)
res.c[i][j] = (res.c[i][j] + x.c[i][k] * y.c[k][j] % mod) % mod;
return res;
} martix fun(char a[12]) {
martix res;
for(int i = 0; i < m; i++)
for(int j = 0; j < m; j++) res.c[i][j] = 0; for(int i = 0; i < m; i++) {
if(a[i] == '0') {
int l = i, r = i;
while(l - 1 >= 0 && a[l - 1] == '0') l--;
while(r + 1 < m && a[r + 1] == '0') r++;
for(int j = l; j <= r; j++) res.c[i][j] = 1;
}
}
return res;
} void pushup(int rt) {
sum[rt] = mul(sum[rt << 1], sum[rt << 1 | 1]);
} void build(int l, int r, int rt) {
if(l == r) {
sum[rt] = fun(s[l]);
return;
} int m = l + r >> 1;
build(l, m, rt << 1);
build(m + 1, r, rt << 1 | 1);
pushup(rt);
} void update(int k, int l, int r, int rt) {
if(l == r) {
sum[rt] = fun(s[k]);
return;
} int m = l + r >> 1;
if(k <= m) update(k, l, m, rt << 1);
else update(k, m + 1, r, rt << 1 | 1);
pushup(rt);
} int main() {
scanf("%d%d%d", &n, &m, &t);
for(int i = 1; i <= n; i++) {
scanf("%s", s[i]);
} build(1, n, 1);
while(t--) {
int opt, a, b;
scanf("%d%d%d", &opt, &a, &b);
if(opt == 1) {
if(s[a][b - 1] == '0') s[a][b - 1] = '1';
else s[a][b - 1] = '0';
update(a, 1, n, 1);
} else if(opt == 2) {
printf("%lld\n", sum[1].c[a - 1][b - 1]);
}
}
return 0;
}
E MASE
F Partition problem
签到题
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll ans;
int n; ll q[30][30];
ll sum[30];
int id[30];
void dfs(int now, int tot, ll val) {
if(tot == n) {
ans = max(ans, val);
return;
}
if(now > n * 2) return; for(int i = now; i <= n * 2; i++) {
ll tmp = val + sum[i];
for(int j = 1; j <= tot; j++) tmp -= q[i][id[j]] * 2LL;
tot++;
id[tot] = i;
dfs(i + 1, tot, tmp);
tot--;
}
return;
} int main() {
ans = 0;
scanf("%d", &n);
for(int i = 1; i <= n * 2; i++) {
for(int j = 1; j <= n * 2; j++) {
scanf("%lld", &q[i][j]);
sum[i] += q[i][j];
}
} dfs(1, 0, 0);
printf("%lld\n", ans);
return 0;
}
F Partition problem
2019牛客多校 Round2的更多相关文章
- 2019牛客多校第一场 I Points Division(动态规划+线段树)
2019牛客多校第一场 I Points Division(动态规划+线段树) 传送门:https://ac.nowcoder.com/acm/contest/881/I 题意: 给你n个点,每个点有 ...
- 2019牛客多校第二场 A Eddy Walker(概率推公式)
2019牛客多校第二场 A Eddy Walker(概率推公式) 传送门:https://ac.nowcoder.com/acm/contest/882/A 题意: 给你一个长度为n的环,标号从0~n ...
- 2019牛客多校第八场 F题 Flowers 计算几何+线段树
2019牛客多校第八场 F题 Flowers 先枚举出三角形内部的点D. 下面所说的旋转没有指明逆时针还是顺时针则是指逆时针旋转. 固定内部点的答案的获取 anti(A)anti(A)anti(A)或 ...
- 2019牛客多校 Round4
Solved:3 Rank:331 B xor 题意:5e4个集合 每个集合最多32个数 5e4个询问 询问l到r个集合是不是都有一个子集的xor和等于x 题解:在牛客多校第一场学了线性基 然后这个题 ...
- 2019牛客多校第一场E ABBA(DP)题解
链接:https://ac.nowcoder.com/acm/contest/881/E 来源:牛客网 ABBA 时间限制:C/C++ 2秒,其他语言4秒 空间限制:C/C++ 524288K,其他语 ...
- 2019牛客多校第四场 I题 后缀自动机_后缀数组_求两个串de公共子串的种类数
目录 求若干个串的公共子串个数相关变形题 对一个串建后缀自动机,另一个串在上面跑同时计数 广义后缀自动机 后缀数组 其他:POJ 3415 求两个串长度至少为k的公共子串数量 @(牛客多校第四场 I题 ...
- 2019牛客多校第四场 A meeting
链接:https://ac.nowcoder.com/acm/contest/884/A来源:牛客网 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 524288K,其他语言10485 ...
- [2019牛客多校第二场][G. Polygons]
题目链接:https://ac.nowcoder.com/acm/contest/882/G 题目大意:有\(n\)条直线将平面分成若干个区域,要求处理\(m\)次询问:求第\(q\)大的区域面积.保 ...
- 2019 牛客多校第一场 D Parity of Tuples
题目链接:https://ac.nowcoder.com/acm/contest/881/D 看此博客之前请先参阅吕凯飞的论文<集合幂级数的性质与应用及其快速算法>,论文中很多符号会被本文 ...
随机推荐
- MySQL45讲:一条update语句是怎样执行的
首先创建一张表: create table T(ID int primary key,c int); 如果要更新ID=2这行+1:应该这样写 update T set c=c+1 where ID=2 ...
- Java 使用 commons-fileupload 实现文件上传工具类
依赖包 文件上传可以使用 Apache 文件上传组件, commons-fileupload, 它依赖于 commons-io commons-io.jar: https://repo1.maven. ...
- 【Git】5、Git如何提交代码到远程仓库
提交代码:如何把修改后的代码提交到远程仓库 文章目录 提交代码:如何把修改后的代码提交到远程仓库 1.同步远程代码 2.检查改动文件 3.添加文件到缓存 4.提交代码 5.推送代码 6.我的整个流程 ...
- ALV中layout布局控制详解
参数的结构为SLIS_LAYOUT_ALV.结构中比较常用的字段如下: no_colhead 隐藏列标题 值为X或空 no_hotspot headings不作为热 ...
- 并发条件队列之Condition 精讲
1. 条件队列的意义 Condition将Object监控器方法( wait , notify和notifyAll )分解为不同的对象,从而通过与任意Lock实现结合使用,从而使每个对象具有多个等待集 ...
- jQuery 选项卡切换过渡效果
<!DOCTYPE html> <head> <meta charset="utf-8"> <title></title> ...
- https://learnku.com/docs/go-blog/qihoo/6532 。 heap size went up to 69G, with maximum garbage collection (GC)
https://learnku.com/docs/go-blog/qihoo/6532 Use a Task Pool, a mechanism with a group of long-lived ...
- Advanced Go Concurrency Patterns
https://talks.golang.org/2013/advconc.slide#5 It's easy to go, but how to stop? Long-lived programs ...
- Centos虚拟机上安装部署Tenginx,以及部署过程中遇到的问题
Tenginx下载网址: Tenginx 官网地址:http://tengine.taobao.org/ Tenginx的官方网址中可以阅读Nginx的文档,可以选择中文进行阅读.下载Tengine- ...
- CF1433F Zero Remainder Sum
写在前面 思维难度不是很大的 DP,代码实现也很容易. 状态设计模式很套路,转移也很好理解. 算法思路 (因为 \(k\) 是常用的循环变量,下文中将题面中的模数改为 \(p\)) 虽然要求的是模 \ ...