HDU 4778 memory-based search & Compression

Source: Internet
Author: User

Give G kinds of gems, B bags, and S, S represents the time when each color of the gem together S can become a magic stone

There are N kinds of gems in each bag, which are c1, c2 .......

Then the two take the bag in turn, each of which can only be taken once, and take out the bag to put the gem on the ground.
If it turns into a magic stone, it will take away the magic stone. The next time this person will take the bag, it will change if it does not become a magic stone.
The Magic Stone number is to get the score and ask the best time difference between the two.


Shape-pressure memory search

A total of 21 packages are saved in the status of the current package.

No matter how it is retrieved, the number of magic stones finally obtained is certain.

Dp [I] indicates the highest score that can be obtained by the first hand in the I state.


# Include "stdio. h "# include" string. h "int aim, g, B, s; int dp [1 <22], c [25] [10]; int bit [25]; int inf = 0x3f3f3f; int Max (int a, int B) {if (a <B) return B; else return a;} int dfs (int cur, int sum, int temp []) {int ans, I, next, j, w, cnt; int mark [10]; if (cur = aim | sum = 0) return 0; if (dp [cur]! = Inf) return dp [cur]; ans = 0; for (I = 1; I <= B; I ++) if (cur & bit [I]) {next = cur ^ bit [I]; cnt = 0; for (j = 1; j <= g; j ++) {mark [j] = temp [j] + c [I] [j]; cnt + = mark [j]/s; mark [j] % = s ;} if (cnt> 0) w = cnt + dfs (next, sum-cnt, mark); else w = sum-dfs (next, sum, mark ); ans = Max (ans, w);} return dp [cur] = ans;} int main () {int I, n, x, sum, aim, ans; int all [10], mark [25]; bit [1] = 1; for (I = 2; I <= 22; I ++) bit [I] = bit [i-1] * 2; while (scanf ("% d % D ", & g, & B, & s )! = EOF) {if (g + B + s = 0) break; memset (c, 0, sizeof (c); memset (all, 0, sizeof (all); for (I = 1; I <= B; I ++) {scanf ("% d", & n); while (n --) {scanf ("% d", & x); c [I] [x] ++; all [x] ++ ;}} sum = 0; for (I = 1; I <= g; I ++) sum + = all [I]/s; aim = bit [B + 1]-1; memset (mark, 0, sizeof (mark); memset (dp, inf, sizeof (dp); ans = dfs (0, 0, mark); printf ("% d \ n ", ans-(sum-ans);} return 0 ;}


HDU 4778 memory-based search & Compression

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.