HDU 4066 2011ACM福州网络赛

Random Sequence

Time Limit: 3000/1000 MS (Java/Others)Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 98Accepted Submission(s): 51


Problem Description
There is a random sequence L whose element are all random numbers either -1 or 1 with the same possibility. Now we define MAVS, the abbreviate of Maximum Absolute Value Subsequence, to be any (if more than one) subsequences of L whose absolute value is maximum among all subsequences. Given the length of L, your task is to find the expectation of the absolute value of MAVS.

Input
There is only one input file. The first line is the number of test cases T. T positive integers follow, each of which contains one positive number not greater than 1500 denoted the length of L.

Output
For each test case, output the expectation you are required to calculate. Answers are rounded to 6 numbers after the decimal point.(as shown in the sample output)

Sample Input
 
 
3 1 5 10

Sample Output
 
 
Case 1: 1.000000 Case 2: 2.750000 Case 3: 4.167969

Source
我也不知道怎么做
反正是写了个暴力的程序,找规律过掉的。。嘿嘿
代码:
#include<stdio.h> double ans[1505]; int main() { int i,n; double x=1.0; ans[1]=1.0; for(i=2;i<=1500;i++) { if(i%2==0) x=x*(i-1.0)/(i*1.0); ans[i]=ans[i-1]+x; } int t,T; scanf("%d",&T); for(t=1;t<=T;t++) { scanf("%d",&n); printf("Case %d: %.6lf\n",t,ans[n]); } return 0; }
暴力的打表程序:
#include<stdio.h> #include<string.h> #include<stdlib.h> main(){ int i,j,k,m=1,temp,temp1,temp2,Max1,Max2,len; double a[100]; for(i=1;i<=26;i++){ len=0; m*=2; for(j=0;j<m;j++){ temp1=temp2=Max1=Max2=0; temp=j; for(k=1;k<=i;k++){ if(temp%2==0) {temp1++;temp2--;} else {temp1--;temp2++;} if(temp1<0) temp1=0; if(temp2<0) temp2=0; temp/=2; if(Max1<temp1) Max1=temp1; if(Max2<temp2) Max2=temp2; } len+=Max1>Max2?Max1:Max2; } printf("%d: %d %d %.6lf\n",i,len,m,(len*1.0)/(m*1.0)); a[i]=(len*1.0)/(m*1.0); } for(i=2;i<=26;i++) printf("%.15lf\n",a[i]-a[i-1]); return 0; }
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值