题目描述
When he checked the detailed status of the submission, there were N test cases in the problem, and the code received TLE in M of those cases.
Then, he rewrote the code to correctly solve each of those M cases with 1⁄2 probability in 1900 milliseconds, and correctly solve each of the other N−M cases without fail in 100 milliseconds.
Now, he goes through the following process:
Submit the code.
Wait until the code finishes execution on all the cases.
If the code fails to correctly solve some of the M cases, submit it again.
Repeat until the code correctly solve all the cases in one submission.
Let the expected value of the total execution time of the code be X milliseconds. Print X (as an integer).
Constraints
All input values are integers.
1≤N≤100
1≤M≤min(N,5)
输入
N M
输出
样例输入
1 1
样例输出
3800
提示
In this input, there is only one case. Takahashi will repeatedly submit the code that correctly solves this case with 1⁄2 probability in 1900 milliseconds.
The code will succeed in one attempt with 1⁄2 probability, in two attempts with 1⁄4 probability, and in three attempts with 1⁄8 probability, and so on.
Thus, the answer is 1900×1⁄2+(2×1900)×1⁄4+(3×1900)×1⁄8+…=3800.
解:Repeat until the code correctly solve all the cases in one submission.,一定要注意这句话,他的意思是重复这句话“Then, he rewrote the code to correctly solve each of those M cases with 1⁄2 probability in 1900 milliseconds, and correctly solve each of the other N−M cases without fail in 100 milliseconds.”再重写这m个问题
理解1:
首先感谢dalao写的,转一下。
https://blog.youkuaiyun.com/winter2121/article/details/81489377
令x=1900m+100(n-m),即每次提交需要花费的时间
令p=1/(2^m),意思是 某次提交,m组超时的数据全部通过的概率
期望公式,k是提交次数,下面我们求出提交次数的数学期望来,再乘上每次的耗时,就是耗时期望了。
k的解释:第一次提交耗时x,第二次2x,第n次就是nx
第一次提交的贡献:1*p
第二次提交的贡献:2*(1-p)*p ( (1-p)*p表示第一次提交没通过,并且第二次通过的概率)
第三次提交的贡献:3*(1-p)^2*p ( (1-p)^2*p 表示前两次提交都没通过,并且第三次通过的概率)
第四次.....一直到第正无穷项。。。
将上面的式子加起来得:
令 ①式
则 ②式
其实这个1.2式就是等差数列与等比数列想乘的前n项和,写出Sn,q*Sn,相减即可。
①-②得:
根据等比数列前n项和公式可得:
化简可得:
由于k趋向于正无穷,其中被减数有一项k作为指数,那被减数的指定服从这个值。因为1-p<1,所以被减数趋近于0
故
所以
这就是提交次数的期望,再乘上1900m+100(n-m)即为答案;
理解2:
虽说比较简单,但是不容易想到这个。。。
代码如下:
#include<bits/stdc++.h> using namespace std; typedef long long ll; int main() { ll n,m; cin>>n>>m; cout<<(100*(n-m)+1900*m)*(1<<m)<<endl; return 0; }
好吧,就这些,再次感谢dalao。
Ooooooo