Poj1157 flower shop (Dynamic Planning)

Source: Internet
Author: User

Simple Dynamic Planning is basically the same as that of a backpack. It should be noted that initialization and the original order must be ensured.

# Include <stdio. h> # define INF-999999int F, V; int A [100] [100]; int d [100] [100]; int dp (int f, int V) {If (d [f] [v]! = Inf) {return d [f] [v];} If (F> V) {// return INF;} If (F = V) {// The vase is enough. put int I in order; int result = 0; for (I = 0; I <= V; I ++) {result + = A [I] [I];} d [f] [v] = result; return result;} int x = dp (F-1, v-1) + A [f] [v]; // F put into Vint y = dp (F, v-1); // F do not put vx = x> Y? X: Y; d [f] [v] = x; return X;} int main (void) {scanf ("% d", & F, & V ); int I, j; for (I = 0; I <F; I ++) {for (j = 0; j <v; j ++) {scanf ("% d", & A [I] [J]); D [I] [J] = inf ;}} printf ("% d \ n ", DP (F-1, V-1); Return 0 ;}

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.