Bzoj1021 [shoi2008] debt cyclic debt

Source: Internet
Author: User

It seems that I have heard of this question last summer... At that time, YY had a plane with three axes, and the angle between axes/3...

Correct solution... Of course DP.

F [I] [J] [k] indicates the I-th nominal value. The first person has J yuan, and the second person has a minimum exchange of K yuan.

So it's just a question about the backpack. Because the DP equation is too complicated, please refer to the program...

(There is also a very powerful pruning program I did not add, because it is too lazy ≥ v ≤ ...... Success! Don't hit me ~~~ Qaq)

 

 1 /************************************************************** 2     Problem: 1021 3     User: rausen 4     Language: C++ 5     Result: Accepted 6     Time:516 ms 7     Memory:8696 kb 8 ****************************************************************/ 9  10 #include <cstdio>11 #include <cstring>12 #include <algorithm>13  14 using namespace std;15 const int n = 6;16 const int M = 1005;17 const int val[n] = {1, 5, 10, 20, 50, 100};18 int x1, x2, x3;19 int now, tot;20 int i, j, k, a, b, suma, sumb, dis;21 int sum[3], Cnt[n];22 int d[2][M][M], cnt[3][n];23  24 inline void update(int &x, int y){25     if (x == -1) x = y;26     else x = min(x, y);27 }28  29 inline int calc(){30     return (abs(a - cnt[0][i]) + abs(b - cnt[1][i]) + abs(Cnt[i] - a - b - cnt[2][i])) / 2;31 }32  33 int main(){34     scanf("%d%d%d", &x1, &x2, &x3);35     for (i = 0; i < 3; ++i){36         sum[i] = 0;37         for (j = n - 1; j >= 0; --j){38             scanf("%d", cnt[i] + j);39             Cnt[j] += cnt[i][j];40             sum[i] += cnt[i][j] * val[j];41         }42         tot += sum[i];43     }44      45     memset(d[0], -1, sizeof(d[0]));46     d[0][sum[0]][sum[1]] = 0;47     for (i = 0; i < n; ++i){48         now = i & 1;49         memset(d[now ^ 1], -1, sizeof(d[now ^ 1]));50         for (j = 0; j <= tot; ++j){51             for (k = 0; j + k <= tot; ++k){52                 if (d[now][j][k] >= 0){53                     update(d[now ^ 1][j][k], d[now][j][k]);54                     for (a = 0; a <= Cnt[i]; ++a){55                         for (b = 0; a + b <= Cnt[i]; ++b){56                             suma = j + val[i] * (a - cnt[0][i]);57                             sumb = k + val[i] * (b - cnt[1][i]);58                             if (suma >= 0 && sumb >= 0 && suma + sumb <= tot){59                                 dis = calc();60                                 update(d[now ^ 1][suma][sumb], d[now][j][k] + dis);61                             }62                         }63                     }64                 }65             }66         }67     }68     int ea = sum[0], eb = sum[1], ec = sum[2];69     ea += x3 - x1, eb += x1 - x2, ec += x2 - x3;70     if (ea < 0 || eb < 0 || ec < 0 || ea + eb + ec != tot || d[n & 1][ea][eb] < 0)71         printf("impossible\n");72     else printf("%d\n", d[n & 1][ea][eb]);73     return 0;74 }
View code

 

Bzoj1021 [shoi2008] debt cyclic debt

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.