CF1009E [Intercity Travelling]】的更多相关文章

这道题先考虑一种暴力n方做法 设\(f_i\)表示到\(i\)点所有情况的困难度之和(\(f_0=0\)),\(pre_i=\sum_{j=1}^{i} a_j\) 考虑从点\(j\)中途不经过休息站到达\(i\),可以得到\[f_i=pre_i+\ \sum_{j=1}^{i-1} f_j+2^{j-1}pre_{i-j}\] (要乘\(2^{j-1}\)是因为到第\(j\)个点有那么多方案) 这个很容易就能优化到\(O(n)\) 记\(g_i=\sum_{j=1}^{i} f_j,h_i=p…
E. Intercity Travelling time limit per test 1.5 seconds memory limit per test 256 megabytes input standard input output standard output Leha is planning his journey from Moscow to Saratov. He hates trains, so he has decided to get from one city to an…
题目描述: D. Intercity Travelling time limit per test 1.5 seconds memory limit per test 256 megabytes input standard input output standard output Leha is planning his journey from Moscow to Saratov. He hates trains, so he has decided to get from one city…
1009 E. Intercity Travelling 题意:一段路n个点,走i千米有对应的a[i]疲劳值.但是可以选择在除终点外的其余n-1个点休息,则下一个点开始,疲劳值从a[1]开始累加.休息与不休息等概率,设疲劳值总和的期望为p,求p*2n-1 思路:由于期望乘上了2n-1,所以数学意义就是求所有休息情况下的疲劳值总和.问题转化为,每种疲劳出现的次数Ni.网上题解大多数从组合数的角度计数,可能是我理解能力不够,总觉得讲的不太严谨,推导的过程略显随意,更多像是找规律的结果.琢磨了一会,觉…
题目链接 大意:一段旅途长度N,中间可能存在N-1个休息站,连续走k长度时,疲劳值为a1+a2+...+aka_1+a_2+...+a_ka1​+a2​+...+ak​,休息后a1a_1a1​开始计,设PPP为疲劳值的期望,问p∗2n−1取模998244353p*2^{n-1}取模998244353p∗2n−1取模998244353的答案. 转自链接 求出每个疲劳值的使用概率,加在一起,乘一下就行了. #include<bits/stdc++.h> #define LL long long #…
题面在这里! 可以发现全是求和,直接拆开算贡献就好了 #include<bits/stdc++.h> #define ll long long using namespace std; const int ha=998244353,N=1e6+5; inline int read(){ int x=0; char ch=getchar(); for(;!isdigit(ch);ch=getchar()); for(;isdigit(ch);ch=getchar()) x=x*10+ch-'0'…
题目链接:http://codeforces.com/contest/1009/problem/E 解题心得: 一个比较简单的组合数学,还需要找一些规律,自己把方向想得差不多了但是硬是找不到规律,还是看了大佬博客才知道的规律.这个题要预先处理2的n次方,不然快速幂也会TLE. 推荐两个大佬的博客: https://blog.csdn.net/u010746456/article/details/81057082 https://blog.csdn.net/hyp1231/article/deta…
大意: 有一段$n$千米的路, 每一次走$1$千米, 每走完一次可以休息一次, 每连续走$x$次, 消耗$a[1]+...+a[x]$的能量. 休息随机, 求消耗能量的期望$\times 2^{n-1}$. 简单计数题, 枚举每种长度的贡献. #include <iostream> #include <algorithm> #include <cstdio> #define REP(i,a,n) for(int i=a;i<=n;++i) using namesp…
题目:戳这里 题意:从0走到n,难度分别为a1~an,可以在任何地方休息,每次休息难度将重置为a1开始.求总难度的数学期望. 解题思路: 跟这题很像,利用期望的可加性,我们分析每个位置的状态,不管怎么休息位置1的难度永远是a1,因此其期望为a1*2^(n-1),其他点出现a1的话,说明上一个点绝对休息过,剩下的都与其无关,也就是2^(n-2),所有的统计起来,则a1的出现次数为2^(n-1)+(n-1)*2^(n-2).同理求a2,a2绝对不会出现在位置1,而出现在位置2时,只会影响位置1,出现…
题目链接 题目大意: 一个人要从$A$地前往$B$地,两地相距$N$千米,$A$地在第$0$千米处,$B$地在第$N$千米处. 从$A$地开始,每隔$1$千米都有$\dfrac{1}{2}$的概率拥有一个休息点, 如果这个地方有休息点的话,这个人就可以在此地休息,起点处(即第$0$千米处)一定是一个休息点. 如果这个人在最近一次休息后行驶了$i$千米,那么他将有$\sum_{j=1}^ia_i$疲劳值. 给出$N$与$a_i(i$为整数且$i\in[1,N])$,求这个人到达$B$地后拥有的疲劳…
题目链接:http://codeforces.com/contest/1009 A. Game Shopping 题目: 题意:有n件物品,你又m个钱包,每件物品的价格为ai,每个钱包里的前为bi.你站在第一件物品前,如果你的第一个钱包能购买这件物品,你第一个钱包的钱直接消失(就相当于你是用第一个钱包里的所有钱购买了这件物品,不会找钱),如果无法购买那么就跳到下一件物品,以此类推,问你总共能购买多少件物品. 思路:直接模拟即可. 代码如下: #include <bits/stdc++.h> u…
目录 Codeforces 1009 A.Game Shopping B.Minimum Ternary String C.Annoying Present D.Relatively Prime Graph E.Intercity Travelling(递推) \(Description\) \(Solution\) F.Dominant Indices(启发式合并) G.Allowed Letters(Hall定理 位运算) \(Description\) \(Solution\) Codef…
A. Game Shopping 签. #include <bits/stdc++.h> using namespace std; #define N 1010 int n, m, c[N]; queue <int> q; int main() { while (scanf("%d%d", &n, &m) != EOF) { while (!q.empty()) q.pop(); ; i <= n; ++i) scanf("%d&…
A. Game Shopping 按照题意模拟既可. #include <iostream> #include <cstdio> using namespace std; const int N = 1010; int n, m, c[N], a[N], ans = 0; int main(){ scanf("%d%d", &n, &m); for(int i = 1; i <= n; i++) scanf("%d",…
Travelling Salesman   After leaving Yemen, Bahosain now works as a salesman in Jordan. He spends most of his time travelling between different cities. He decided to buy a new car to help him in his job, but he has to decide about the capacity of the…
After leaving Yemen, Bahosain now works as a salesman in Jordan. He spends most of his time travelling between different cities. He decided to buy a new car to help him in his job, but he has to decide about the capacity of the fuel tank. The new car…
Travelling Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 2554    Accepted Submission(s): 746 Problem DescriptionAfter coding so many days,Mr Acmer wants to have a good rest.So travelling is th…
Travelling Tours Time limit: 1.0 secondMemory limit: 64 MB There are N cities numbered from 1 to N (1 ≤ N ≤ 200) and M two-way roads connect them. There are at most one road between two cities. In summer holiday, members of DSAP Group want to make so…
http://acm.hdu.edu.cn/showproblem.php?pid=3001 从任何一个点出发,去到达所有的点,但每个点只能到达2次,使用的经费最小.三进制 Travelling Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 3541    Accepted Submission(s): 1106 Problem Des…
1616: [Usaco2008 Mar]Cow Travelling游荡的奶牛 Time Limit: 5 Sec  Memory Limit: 64 MBSubmit: 1006  Solved: 548[Submit][Status][Discuss] Description 奶牛们在被划分成N行M列(2 <= N <= 100; 2 <= M <= 100)的草地上游走,试图找到整块草地中最美味的牧草.Farmer John在某个时刻看见贝茜在位置 (R1, C1),恰好T…
1616: [Usaco2008 Mar]Cow Travelling游荡的奶牛 Time Limit: 5 Sec  Memory Limit: 64 MBSubmit: 762  Solved: 427[Submit][Status] Description 奶牛们在被划分成N行M列(2 <= N <= 100; 2 <= M <= 100)的草地上游走,试图找到整块草地中最美味的牧草.Farmer John在某个时刻看见贝茜在位置 (R1, C1),恰好T (0 < T…
一道水 dp ...然后我一开始用 BFS ...结果 MLE 了... dp[ i ][ j ][ k ] 由它四个方向上的 k - 1 转移. ----------------------------------------------------------------------------------------------- #include<cstdio> #include<algorithm> #include<cstring> #include<…
Travelling Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 3905    Accepted Submission(s): 1234 Problem Description After coding so many days,Mr Acmer wants to have a good rest.So travelling is…
Travelling Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 6600    Accepted Submission(s): 2144 Problem Description After coding so many days,Mr Acmer wants to have a good rest.So travelling is…
题目连接:http://acm.hdu.edu.cn/showproblem.php?pid=3001 Travelling Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 5295    Accepted Submission(s): 1718 Problem Description After coding so many days,…
The "travelling salesman problem" asks the following question: "Given a list of cities and the distances between each pair of cities, what is the shortest possible route that visits each city and returns to the origin city?" It is an N…
Problem B. Travelling Camera Problem 题目连接: http://www.codeforces.com/gym/100253 Description Programming competitions become very popular in Berland. Now Berland Broadcasting Corporation (BBC) plans to organize a TV broadcast of the All-Berland Region…
TEXT 6 Travelling with baggage 背着行囊去旅行 Feb 16th 2006 From The Economist print edition (1)FEW modern travel writers excite more hostility and awe than Sir ★Wilfred Thesiger[1], who died in 2003. Despising the “drab uniformity of the modern world”, Sir…
题目链接:Travelling Salesman and Special Numbers 题意: 给出一个二进制数n,每次操作可以将这个数变为其二进制数位上所有1的和(3->2 ; 7->3),现在给出了一个数k,问不大于n的数中有几个数经过k次操作可以变成1. 题解: 因为所给的n很大,但是可以发现只要经过一次操作,n都会变成1000以内的数,所以可以把1000以内的数的答案都存下来.每次在这里面找等于k-1的数,然后数位DP求个数. #include<bits/stdc++.h>…
题目链接:Travelling Salesman and Special Numbers 题意: 给了一个n×m的图,图里面有'N','I','M','A'四种字符.问图中能构成NIMA这种序列最大个数(连续的,比如说NIMANIMA = 2)为多少,如果有环的话那么最大长度就是无穷. 题解: 哇,做了这题深深得感觉自己的dfs真的好弱.这题就是从N开始深搜,在深搜的过程中记录值.返回这个值加1. //#pragma comment(linker, "/stack:200000000"…