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的更多相关文章

  1. 2019牛客多校第一场 I Points Division(动态规划+线段树)

    2019牛客多校第一场 I Points Division(动态规划+线段树) 传送门:https://ac.nowcoder.com/acm/contest/881/I 题意: 给你n个点,每个点有 ...

  2. 2019牛客多校第二场 A Eddy Walker(概率推公式)

    2019牛客多校第二场 A Eddy Walker(概率推公式) 传送门:https://ac.nowcoder.com/acm/contest/882/A 题意: 给你一个长度为n的环,标号从0~n ...

  3. 2019牛客多校第八场 F题 Flowers 计算几何+线段树

    2019牛客多校第八场 F题 Flowers 先枚举出三角形内部的点D. 下面所说的旋转没有指明逆时针还是顺时针则是指逆时针旋转. 固定内部点的答案的获取 anti(A)anti(A)anti(A)或 ...

  4. 2019牛客多校 Round4

    Solved:3 Rank:331 B xor 题意:5e4个集合 每个集合最多32个数 5e4个询问 询问l到r个集合是不是都有一个子集的xor和等于x 题解:在牛客多校第一场学了线性基 然后这个题 ...

  5. 2019牛客多校第一场E ABBA(DP)题解

    链接:https://ac.nowcoder.com/acm/contest/881/E 来源:牛客网 ABBA 时间限制:C/C++ 2秒,其他语言4秒 空间限制:C/C++ 524288K,其他语 ...

  6. 2019牛客多校第四场 I题 后缀自动机_后缀数组_求两个串de公共子串的种类数

    目录 求若干个串的公共子串个数相关变形题 对一个串建后缀自动机,另一个串在上面跑同时计数 广义后缀自动机 后缀数组 其他:POJ 3415 求两个串长度至少为k的公共子串数量 @(牛客多校第四场 I题 ...

  7. 2019牛客多校第四场 A meeting

    链接:https://ac.nowcoder.com/acm/contest/884/A来源:牛客网 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 524288K,其他语言10485 ...

  8. [2019牛客多校第二场][G. Polygons]

    题目链接:https://ac.nowcoder.com/acm/contest/882/G 题目大意:有\(n\)条直线将平面分成若干个区域,要求处理\(m\)次询问:求第\(q\)大的区域面积.保 ...

  9. 2019 牛客多校第一场 D Parity of Tuples

    题目链接:https://ac.nowcoder.com/acm/contest/881/D 看此博客之前请先参阅吕凯飞的论文<集合幂级数的性质与应用及其快速算法>,论文中很多符号会被本文 ...

随机推荐

  1. vue-vite浅析

    大家好,我是小雨小雨,致力于分享有趣的.实用的文章. 内容分为原创和翻译,如果有问题,欢迎随时评论或私信,很乐意和大家一起探讨,一起进步. 分享不易,希望能够得到大家的支持和关注. vite出了好久了 ...

  2. 微信小程序API交互的自定义封装

    目录 1,起因 2,优化成果 3,实现思路 4,完整代码 1,起因 哪天,正在蚂蚁森林疯狂偷能量的我被boss叫过去,告知我司要做一个线上直播公开课功能的微信小程序,博主第一次写小程序,复习了下文档, ...

  3. SwiftUI 中一些和响应式状态有关的属性包装器的用途

    SwiftUI 借鉴了 React 等 UI 框架的概念,通过 state 的变化,对 View 进行响应式的渲染.主要通过 @State, @StateObject, @ObservedObject ...

  4. 鸿蒙的多媒体及Menu组件及小程序的多媒体组件

    目录: js业务逻辑层 视图渲染层 css属性设置 效果图 微信小程序展示 内网穿透工具下载 我们在搭建一个小程序或者网站的时候,往往要加载很多的图片,音频和视频文件.如果都从服务器获取静态资源,这样 ...

  5. uni-app 开发随笔(踩坑记录)

    这里总结一些uni-app开发时我遇到的坑 uni-app获取元素高度及屏幕高度(uni-app不可使用document) uni.getSystemInfo({ success: function( ...

  6. Arduino 上手实战呼吸灯

    前言 这篇稿子比以往的时候来的稍晚了一些,望fans们见谅,那即便如此,最终还是姗姗来迟了,公司新一轮战略性部署,被拖出去孵化新产品,开拓新市场去了,手头精力没有那么多了,另外产品一茬接一茬.韭菜一波 ...

  7. 将ffmpeg编译为wasm版本且在浏览器中运行

    2020年大前端技术趋势解读 原创 IMWeb团队 腾讯IMWeb前端团队 5天前

  8. 使用Linux服务器来通过网络安装和激活Windows 7 —— 一些基本原理

    使用Linux服务器来通过网络安装和激活Windows 7 -- 一些基本原理 https://www.pufengdu.org/blog/?p=372

  9. Transformation-Based Error-Driven Learning and Natural Language Processing: A Case Study in Part-of-Speech Tagging

    http://delivery.acm.org/10.1145/220000/218367/p543-brill.pdf?ip=116.30.5.154&id=218367&acc=O ...

  10. JavaScript与多线程的不解之缘!

    前言 对于前端开发者来说,多线程是一个比较陌生的话题.因为JavaScript是单线程语言.也就是说,所有任务只能在一个线程上完成,一次只能做一件事.前面的任务没做完,后面的任务只能等着. UI渲染与 ...