2019南京网络赛 D Robots 期望dp】的更多相关文章

题目传送门 题意:给出一幅有向无环图,保证只有1入度为0,n出度为0,求问一个机器人从1出发,每天等概率的走到相邻点或者留在原地,问到达n点的代价.每天的代价都不一样,就是天数(第x天走一步的代价就是x). 思路:设出度每个点的选择情况为$cnt[i]$,即出度加1. 由于每天的代价和天数有关,所以应该要想到,可以先算出天数的期望.这样就可以得到每个点的代价,再算总的代价期望. 把一道题拆成两题,简单求解. $dp[u]=dp[u]*\frac{1}{cnt[u]}+\frac{1}{cnt[u…
南京网络赛自闭现场 https://nanti.jisuanke.com/t/41298 二维偏序经典题型 二维前缀和!!! #include<bits/stdc++.h> using namespace std; #define int long long #define sc(x) scanf("%lld",&x); int T; #define P pair<int,int> #define fi first #define se second #…
题目链接 2019.9.2更新 第二天睡醒想了想发现好像搜一遍就可以过,赛时写的花里胡哨的还错了,太菜了QAQ #include<bits/stdc++.h> using namespace std; typedef long long ll; ; struct node { int s, e, next; }edge[maxn]; int head[maxn], len; void init() { memset(head, -, sizeof(head)); len = ; } void…
(施工中……已更新DF) 比赛传送门:https://www.jisuanke.com/contest/3004 D. Robots(期望dp) 题意 给一个DAG,保证入度为$0$的点只有$1$,出度为$0$的点只有$n$. 现在一个机器人从$1$出发,每天都会以相同的概率前往相邻节点之一或静止不动. 每天机器人消耗的耐久等于经过的天数. 求机器人到点$n$期望消耗的耐久. 划水划的很愉快,唯一一道做出来的题.但是和题解做法不同(感觉我的方法麻烦),因此砸了3h在这题上面(正在试图读懂题解in…
Robots \[ Time Limit: 1000 ms \quad Memory Limit: 262144 kB \] 题意 有一个机器人要从 \(1\) 点走到 \(n\) 点,每走一步都需要一天,并且这一步的代价是已经经过的天数. 思路 将问题拆成两个问题,\(dp1[i]\) 表示从 \(i\) 到 \(n\) 的天数期望,\(dp2[i]\) 表示从 \(i\) 到 \(n\) 的代价期望. 那么就很容易得到 \[ dp1[u] = \frac{\sum_{u->v}(dp1[v]…
Description: 定义函数 \[ f _n (k) = \sum _{l _1 = 1} ^n \sum _{l _2 = 1} ^n \cdots \sum _{l _k = 1} ^n \gcd(l _1, l _2, \cdots, l _k) ^2 \] 现给定 \(n, k\),需要求出 \(\sum _{i = 2} ^k f _n (i)\),答案对 \(10 ^9 + 7\) 取模. \(T\) 组数据. \[ 1 \le T \le 10, 1 \le n \le 10…
一.题目 super_log 二.分析 公式很好推出来,就是$$a^{a^{a^{a^{...}}}}$$一共是$b$个$a$. 对于上式,由于指数太大,需要降幂,这里需要用到扩展欧拉定理: 用这个定理时,除了$\gcd (a,p) =1$的情况,其他情况主要是保证$a$的指数不为$0$,在写代码的时候也需要注意这点,当然也可以重新定义个快速幂,使其快速幂的结果保证不为$0$,也是可以的的. 三.AC代码 #include <bits/stdc++.h> using namespace std…
Walk Through Squares Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65535/65535 K (Java/Others)Total Submission(s): 200    Accepted Submission(s): 57 Problem Description   On the beaming day of 60th anniversary of NJUST, as a military colleg…
2018ICPC南京网络赛 A. An Olympian Math Problem 题目描述:求\(\sum_{i=1}^{n} i\times i! \%n\) solution \[(n-1) \times (n-1)! \% n= (n-2)!(n^2-2n+1) \%n =(n-2)!\] \[(n-2+1)\times (n-2)! \% n= (n-3)!(n^2-3n+2) \%n =(n-3)! \times 2\] 以此类推,最终只剩下\(n-1\) 时间复杂度:\(O(1)\…
ICPC 2019 徐州网络赛 比赛时间:2019.9.7 比赛链接:The Preliminary Contest for ICPC Asia Xuzhou 2019 赛后的经验总结 // 比赛完才反应过来没看完全部题, J题树形dp没写太亏了... // 几何旋律AK了,太强了Orz // 虽然我们队A了8题,但如果时间分配好,认真读题避免看错题的话,应该至少多A一题 A. Who is better? 题意 两个人玩游戏,谁先消灭完敌人就赢.两条规则:1. 第一个人不能全部消灭完: 2.…
Divide Groups Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 423    Accepted Submission(s): 161 Problem Description   This year is the 60th anniversary of NJUST, and to make the celebration mor…
Count The Pairs Time Limit: 20000/10000 MS (Java/Others)    Memory Limit: 65535/65535 K (Java/Others)Total Submission(s): 277    Accepted Submission(s): 150 Problem Description   With the 60th anniversary celebration of Nanjing University of Science…
题意:询问区间有多少个连续的段,而且这段的颜色在[L,R]才算贡献,每段贡献是1. 有单点修改和区间查询. 思路:46min交了第一发树套树,T了. 稍加优化多交几次就过了. 不难想到,除了L这个点,其他的点都可以只统计这一段的段首.把位置看成x,颜色看成y,就成了二维平面就矩形内点的个数,这就是裸的树套树或者CDQ了. 树套树:34**ms. /* 2019南昌网络赛I. 询问区间有多少个连续的段,而且这段的颜色在[L,R]才算贡献,每段贡献是1. 有单点修改和区间查询. 也可以CDQ来做,常…
ACM-ICPC 2019南昌网络赛I题 Yukino With Subinterval 题目大意:给一个长度为n,值域为[1, n]的序列{a},要求支持m次操作: 单点修改 1 pos val 询问子区间中某个值域的数的个数,连续的相同数字只记为一个.(即统计数字段的个数) 2 L R x y 数据范围: 1 ≤ n,m ≤ 2×10^5 1 ≤ a[i] ≤ n 解题思路: 连续重复的数字只记一次.所以考虑将每个数字段除第一个出现外的数字都删去(记为0).在读入操作的时候暴力模拟,同时维护…
2019ICPC南京网络赛A题 The beautiful values of the palace https://nanti.jisuanke.com/t/41298 Here is a square matrix of n * nn∗n, each lattice has its value (nn must be odd), and the center value is n * nn∗n. Its spiral decline along the center of the squar…
ACM-ICPC 南昌网络赛F题 Megumi With String 题目描述 给一个长度为\(l\)的字符串\(S\),和关于\(x\)的\(k\)次多项式\(G[x]\).当一个字符串\(str\)是S的子串时,定义\(str\)的\(value\)值为\(G[length(str)]\),否则\(value=0\).一个字符串的\(power\)值定义为其所有子串的\(value\)之和.每次向\(S\)末尾添加一个字符,重复\(m\)次.求每次添加字符后,一个长度为\(n\)的随机串\…
题目链接 题意 : 给出一个由数字组成的字符串.然后要你找出其所有本质不同的回文子串.然后将这些回文子串转化为整数后相加.问你最后的结果是多少.答案模 1e9+7 分析 : 应该可以算是回文树挺裸的题目吧 可惜网络赛的时候不会啊.看着马拉车想半天.卒... 对于每一个节点.记录其转化为整数之后的值 然后在回文串插入字符的时候 不断维护这个信息就行了 其实很好理解.看一下代码就懂了 ( 如果你学过回文树的话... ) 就是多加了变量 val .维护语句 #include<bits/stdc++.h…
Dlsj is competing in a contest with n (0 < n \le 20)n(0<n≤20) problems. And he knows the answer of all of these problems. However, he can submit ii-th problem if and only if he has submitted (and passed, of course) s_isi​ problems, the p_{i, 1}pi,1​…
AC Challenge 30.04% 1000ms 128536K   Dlsj is competing in a contest with n (0 < n \le 20)n(0<n≤20) problems. And he knows the answer of all of these problems. However, he can submit ii-th problem if and only if he has submitted (and passed, of cours…
目录 题目链接 思路 代码 题目链接 传送门 思路 首先我们将原式化简: \[ \begin{aligned} &\sum\limits_{l_1=1}^{n}\sum\limits_{l_2=1}^{n}\dots\sum\limits_{l_k=1}^{n}gcd(l_1,l_2,\dots,l_k)^2&\\ =&\sum\limits_{d=1}^{n}d^2\sum\limits_{l_1=1}^{n}\sum\limits_{l_2=1}^{n}\dots\sum\li…
Rhyme scheme Problem Describe A rhyme scheme is the pattern of rhymes at the end of each line of a poem or song. It is usually referred to by using letters to indicate which lines rhyme; lines designated with the same letter all rhyme with each other…
题目:https://nanti.jisuanke.com/t/41414 题意:求长度为n的第k个bell number  ,  就是第i位的选取范围在 1-(i-1)位的最大值 +1,第一位固定为A,按字典序排列 思路:设立dp[n][i][j]  代表长度n,第i层,第1-i位的最大值是j的方案数…
题目传送门 题意:求一颗树中所有点对(a,b)的路径长度,路径长度按照模3之后的值进行分类,最后分别求每一类的和 分析:树形DP \(dp[i][j]\) 表示以 i 为根的子树中,所有子节点到 i 的路径长度模3等于 j 的路径之和 \(c[i][j]\) 表示以 i 为根的子树中,所有子节点到 i 的路径长度模3等于 j 的点数 \(ok[i][j]\) 表示以 i 为根的子树中,是否有子节点到 i 的路径长度模3等于 j 每次只考虑所有经过根 x 的路径,并且路径的一个端点在 x 的一颗子…
计蒜客题目链接:https://nanti.jisuanke.com/t/41303 题目:给你一个序列a,你可以从其中选取元素,构建n个串,每个串的长度为n,构造的si串要满足以下条件, 1. si[1]=i . 2. si[j]<si[j-1] 3. |pos[j] -pos[j-1]|<=k 并且每个a中的元素只能用一次 4. 两个串大小的定义时 前k项相等的前提(k和前面不是一个),Ck>Dk,则C大于D 求Si的长度,并输出 由于Si[ j ] < Si[j - 1] ,…
You're given a permutation aa of length nn (1 \le n \le 10^51≤n≤105). For each i \in [1,n]i∈[1,n], construct a sequence s_isi​ by the following rules: s_i[1]=isi​[1]=i; The length of s_isi​ is nn, and for each j \in [2, n]j∈[2,n], s_i[j] \le s_i[j-1]…
As the current heir of a wizarding family with a long history,unfortunately, you find yourself forced to participate in the cruel Holy Grail War which has a reincarnation of sixty years.However,fortunately,you summoned a Caster Servant with a powerfu…
During tea-drinking, princess, amongst other things, asked why has such a good-natured and cute Dragon imprisoned Lpl in the Castle? Dragon smiled enigmatically and answered that it is a big secret. After a pause, Dragon added: - We have a contract.…
30.43% 2000ms 262144K Feeling hungry, a cute hamster decides to order some take-away food (like fried chicken for only 3030 Yuan). However, his owner CXY thinks that take-away food is unhealthy and expensive. So she demands her hamster to fulfill a m…
样例输入复制 2 3 3 0 3 3 1 2 2 样例输出复制 Case #1: 36 Case #2: 20 题目来源 ACM-ICPC 2018 南京赛区网络预赛 题意: 就是求图中去掉涂黑的方格后还剩多少长方形 解析: 这个讲的非常好了 https://blog.csdn.net/Sirius_han/article/details/82313029 对于一个长为L, 高为H的无黑点矩阵中包含的高为H的子矩阵个数为L+(L-1)+(L-2)+...+1个:这是直接算的一种方法:如何程序表示…
A square-free integer is an integer which is indivisible by any square number except 11. For example, 6 = 2 \cdot 36=2⋅3 is square-free, but 12 = 2^2 \cdot 312=22⋅3 is not, because 2^222 is a square number. Some integers could be decomposed into prod…