Poj 1609 Tiling Up Blocks dp entry-Memory search, pojtiling

Source: Internet
Author: User

Poj 1609 Tiling Up Blocks dp entry-Memory search, pojtiling

Question:

For n binary groups (a, B), find the longest sequence in the sequence so that any I <j, ai <= aj and bi <= bj in the sequence.

Analysis:

Set dp [a] [B] to represent the longest sequence length ending with (a, B), and perform the Memory search.

Code:

// Poj 1609 // sep9 # include <iostream> using namespace std; const int max_p = 128; int n; int num [max_p] [max_p]; int dp [max_p] [max_p]; int search (int x, int y) {if (dp [x] [y]) return dp [x] [y]; int I, j, maxx = 0; for (I = 1; I <= x; ++ I) for (j = 1; j <= y; ++ j) if (! (I = x & j = y) if (num [I] [j]) maxx = max (maxx, search (I, j )); return dp [x] [y] = maxx + num [x] [y];} int main () {while (scanf ("% d", & n) = 1) {if (n = 0) {printf ("* \ n"); break;} int max_l = 0, max_m = 0; memset (num, 0, sizeof (num); memset (dp, 0, sizeof (dp); for (int I = 0; I <n; ++ I) {int a, B; scanf ("% d", & a, & B); ++ num [a] [B]; max_l = max (max_l, ); max_m = max (max_m, B) ;}int I, j, ans = 0; for (I = 1; I <= max_l; ++ I) for (j = 1; j <= max_m; ++ j) if (num [I] [j]) ans = max (ans, search (I, j )); printf ("% d \ n", ans);} 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.