! Hdu 1203 -- dp -- (deep understanding), hdu1203 -- dp --

Source: Internet
Author: User

! Hdu 1203 -- dp -- (deep understanding), hdu1203 -- dp --

James has n yuan. He wants to apply for a foreign school and apply for the si fee for the I-th school. The probability of successful application is pi, the probability that James can apply for at least one school.

Analysis: the probability is, of course, the minimum value from the opposite side. State transition equation: dp [I] = min (dp [j] * p [I], dp [I]). I think wrong, I traverse according to the previous dp routine according to the array, and sorted first. dp [I] represents the optimal solution when applying for the I school; the correct solution should be based on the cost. dp [I] indicates the optimal solution when I yuan is used. This is the correct idea.

Dp should be further understood!

Code:

# Include <iostream> # include <cstdio> using namespace std; int n, m; int a [10008]; double p [10008], dp [10008]; double DP () {double mi = 1; for (int I = 0; I <m; I ++) {for (int j = n; j-a [I]> = 0; j --) {if (dp [j]> dp [j-a [I] * p [I]) dp [j] = dp [j-a [I] * p [I]; if (mi> dp [j]) mi = dp [j];} return mi;} int main () {while (cin> n> m) {if (! N &&! M) break; for (int I = 0; I <m; I ++) {cin> a [I]> p [I]; p [I] = 1-p [I];} for (int I = 0; I <= n; I ++) dp [I] = 1; double ans = DP (); printf ("% 0.1lf % \ n", 100 * (1-ans ));}}


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.