@AtCoder Beginner Contest 078 C: HSI (数学期望;数学列式相消法)

Problem Statement

Takahashi is now competing in a programming contest, but he received TLE in a problem where the answer is YES or NO.

When he checked the detailed status of the submission, there were NN test cases in the problem, and the code received TLE in MM of those cases.

Then, he rewrote the code to correctly solve each of those MM cases with 1/21/2 probability in 19001900milliseconds, and correctly solve each of the other N−MN−M cases without fail in 100100 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 MM 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 XX milliseconds. Print XX (as an integer).

Constraints

  • All input values are integers.
  • 1≤N≤1001≤N≤100
  • 1≤M≤min(N,5)1≤M≤min(N,5)

Input

Input is given from Standard Input in the following format:

NN MM

Output

Print XX, the expected value of the total execution time of the code, as an integer. It can be proved that, under the constraints in this problem, XX is an integer not exceeding 109109.


Sample Input 1 Copy

Copy

1 1

Sample Output 1 Copy

Copy

3800

In this input, there is only one case. Takahashi will repeatedly submit the code that correctly solves this case with 1/21/2 probability in 19001900 milliseconds.

The code will succeed in one attempt with 1/21/2 probability, in two attempts with 1/41/4 probability, and in three attempts with 1/81/8 probability, and so on.

Thus, the answer is 1900×1/2+(2×1900)×1/4+(3×1900)×1/8+...=38001900×1/2+(2×1900)×1/4+(3×1900)×1/8+...=3800.


Sample Input 2 Copy

Copy

10 2

Sample Output 2 Copy

Copy

18400

The code will take 19001900 milliseconds in each of the 22 cases, and 100100 milliseconds in each of the 10−2=810−2=8 cases. The probability of the code correctly solving all the cases is 1/2×1/2=1/41/2×1/2=1/4.


Sample Input 3 Copy

Copy

100 5

Sample Output 3 Copy

Copy

608000

 

[题意]

m 个题目 都要在 1900 内过, 每个过的概率是1/2    剩下的  n-m 题 一定会在 100 内过

求时间期望:

[思路]

时间 x = 1900*m + 100*(n-m)

过题的概率 p = \frac{1}{2^m}  m 代表某次提交m组全部都过的.

期望为: \sum k*p^{k}  k 是提交次数..

贡献为: 

1*p

2*(1-p)*p

3*(1-p)^2*p

4*(1-p)^3*p

......

n*(1-p)^{n-1}*p

累加起来就是:

 \tiny sum = (1*p) +(2*(1-p)*p)+(3*(1-p)^2*p)+(4*(1-p)^3*p)+.....+(n*(1-p)^{n-1}*p)   

提取 p  放在前面得

① \tiny sum =p*( 1 +(2*(1-p))+(3*(1-p)^2)+(4*(1-p)^3)+.....+(n*(1-p)^{n-1}) )

② \tiny (1-p)*sum = p*( (1*(1-p))+(2*(1-p)^2)+(3*(1-p)^3)+.....+((n-1)*(1-p)^{n-1}) ) +(n*(1-p)^{n}) )

① - ② 得

\tiny p*sum=1+(1-p)^{1}+(1-p)^{2}+....+(1-p)^{n-1}-n(1-p)^{n}

等比公式前n 项和 化简

\tiny p*sum=\frac{1-(1-p)^{n}}{p} -n*(1-p)^{n}

再次化简:

\tiny sum= \frac{1}{p^{2}}-\frac{(1-p)^n*(1+p^{2}*n)}{p^{2}}  n 趋向正无穷,所以后面 趋向 0

\tiny sum= \frac{1}{p^{2}}

所以 期望 = p * sum =  \tiny \frac{1}{p}

然后乘上 x  就是 时间期望

[代码]

#include 
#include 
 
#define rep(i,a,n) for(int  i=a;i<=n;i++)
#define per(i,a,n) for(int i = n;i>=a;i--)
#define Si(x) scanf("%d",&x)
 
using namespace std;
typedef long long ll;
const int inf =0x3f3f3f3f;
const int maxn =1e5+10;
 
int a[maxn];
int main()
{
    int n,m;
    scanf("%d %d",&n,&m);
    ll num = 1ll<

 

你可能感兴趣的:(***数学***,*****递推*****,ACM进阶之路)