CSU 1290 DP solves mathematical expectation Problems

Source: Internet
Author: User

Question link: http://acm.csu.edu.cn/OnlineJudge/problem.php? Id = 1290

Question:

Given the number of K, you can generate any number in 0-n-1 each time. The mathematical expectation of the number of K numbers with different integers

1 # include <cstdio> 2 # include <cstring> 3 using namespace STD; 4 # define n 1005 5 double DP [N]; 6 int main () 7 {8 int t, k, n; 9 scanf ("% d", & T); 10 while (t --) {11 scanf ("% d", & K, & N ); 12 DP [1] = 1.00; 13 for (INT I = 2; I <= N; I ++) {14 DP [I] = DP [I-1] + (k-DP [I-1])/K; 15} 16 printf ("%. 5f \ n ", DP [N]); 17} 18 return 0; 19}

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.