HDU 4599 Dice

Description

Given a normal dice (with 1, 2, 3, 4, 5, 6 on each face), we define: 
F(N) to be the expected number of tosses until we have a number facing up for N consecutive times. 
H(N) to be the expected number of tosses until we have the number '1' facing up for N consecutive times. 
G(M) to be the expected number of tosses until we have the number '1' facing up for M times. 
Given N, you are supposed to calculate the minimal M1 that G (M1) >= F (N) and the minimal M2 that G(M2)>=H(N)
 

Input

The input contains multiple cases. 
Each case has a positive integer N in a separated line. (1<=N<=1000000000) 
The input is terminated by a line containing a single 0.
 

Output

For each case, output the minimal M1 and M2 as required in a single line, separated by a single space. 
Since the answer could be very large, you should output the answer mod 2011 instead.
 

Sample Input

    
    
1 2 0
 

Sample Output

    
    
1 1

2 7

期望dp

主要是推公式http://www.cnblogs.com/allh123/archive/2013/08/25/3281039.html

#include<cstdio>
#include<cstring>
#include<vector>
#include<iostream>
#include<queue>
#include<algorithm>
#include<cmath>
#include<cstdlib>
#include<string>
using namespace std;
const int base = 2011;
const int size = 2;
int n;

int inv(int x)
{
	if (x == 1) return 1;
	else return inv(base % x)*(base - base / x) % base;
}

int get(int x, int y)
{
	int i, j;
	for (i = x, j = 1; y; y >>= 1)
	{
		if (y & 1) (j *= i) %= base;
		(i *= i) %= base;
	}
	return j;
}

void work(int n)
{
	int x = get(6, n) - 1;
	int y = (((x+25) * inv(30) % base) + base) % base;
	int z = ((x * inv(5) % base) + base) % base;
	printf("%d %d\n", y, z);
}

int main()
{
	while (scanf("%d", &n), n) work(n);
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
经导师精心指导并认可、获 98 分的毕业设计项目!【项目资源】:微信小程序。【项目说明】:聚焦计算机相关专业毕设及实战操练,可作课程设计与期末大作业,含全部源码,能直用于毕设,经严格调试,运行有保障!【项目服务】:有任何使用上的问题,欢迎随时与博主沟通,博主会及时解答。 经导师精心指导并认可、获 98 分的毕业设计项目!【项目资源】:微信小程序。【项目说明】:聚焦计算机相关专业毕设及实战操练,可作课程设计与期末大作业,含全部源码,能直用于毕设,经严格调试,运行有保障!【项目服务】:有任何使用上的问题,欢迎随时与博主沟通,博主会及时解答。 经导师精心指导并认可、获 98 分的毕业设计项目!【项目资源】:微信小程序。【项目说明】:聚焦计算机相关专业毕设及实战操练,可作课程设计与期末大作业,含全部源码,能直用于毕设,经严格调试,运行有保障!【项目服务】:有任何使用上的问题,欢迎随时与博主沟通,博主会及时解答。 经导师精心指导并认可、获 98 分的毕业设计项目!【项目资源】:微信小程序。【项目说明】:聚焦计算机相关专业毕设及实战操练,可作课程设计与期末大作业,含全部源码,能直用于毕设,经严格调试,运行有保障!【项目服务】:有任何使用上的问题,欢迎随时与博主沟通,博主会及时解答。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值