Codeforces 283c coin troubles Analysis + backpack thinking

Source: Internet
Author: User

Very flexible questions, simple questions, seeing is a coin problem, similar to the kind that gives a certain number of T, there are n kinds of coins, each value, let you combine the number of solutions with a total value of T, but some restrictions are added, that is, the number of coins of some types must be greater than that of other types, when I added a limit, I lost my head. Alas, I thought I was really not enough. Then I looked at other people's analysis.

If the number of coins of Category A must be greater than that of Category B, then if I want M coins of Category B, it is also equivalent to M coins of category, because a must be greater than B, we can modify the value of the coin given by the question in this way. If the number of A categories must be greater than that of B, and the value of a category is, if the type B is B, you can change the coin of the type B to a + B. At the same time, the total value of T must be subtracted first !!! One !!! The value of the type coin, so that the number of the type can be satisfied as needed. The number of the type is greater than that of the B type.

In this way, we can carry out the idea of imitation Backpacks for Recursive solution.

I suddenly realized that

However, WA has been around for a long time, but now it has become so numerous that it cannot read other people's code and find that there are some more processing items in front of it, for example, if a must be greater than B and B must be greater than C, then C may be larger than, the Q group restriction is given in the question. Each group contains bi. CI indicates that the same number is not repeated in Bi, And neither in CI, however, Bi and CJ may still be the same, so there may be loops, but the reading questions are not careful enough. The questions are good, and it is not difficult to understand the analysis process, but it's a good question.



Http://codeforces.com/contest/283/problem/C



# Include <iostream> # include <cstdio> # include <list> # include <algorithm> # include <cstring> # include <string> # include <queue> # include <stack> # include <map> # include <vector> # include <cmath> # include <memory. h ># include <set> # define ll long # define EPS 1e-8const int INF = 0 xfffffff; const ll INF = 1ll <61; using namespace STD; // vector <pair <int, int> G; // typedef pair <int, int> P; // vector <pair <int, int> >:: iterator I Ter; // Map <LL, int> MP; // Map <LL, int>: iterator P; # define mod 1000000007 int NN [355]; int B [355]; int C [355]; int father [355]; int in [355]; ll DP [1000000 + 5]; bool flag; void Init () {memset (NN, 0, sizeof (NN); memset (B, 0, sizeof (B); memset (C, 0, sizeof (c )); memset (in, 0, sizeof (in); memset (father, 0, sizeof (father); memset (DP, 0ll, sizeof (DP )); flag = false;} void input (Int & N, Int & Q, Int & T) {scanf ("% d", & N, & Q, & T ); For (INT I = 1; I <= N; I ++) scanf ("% d", & NN [I]); For (INT I = 0; I <q; I ++) {scanf ("% d", & B [I], & C [I]); father [B [I] = C [I]; In [C [I] ++ ;}} void CAL (Int & N, Int & Q, Int & T) {for (INT I = 0; I <q; I ++) {int TMP = 0; For (Int J = 1; j <= N; j ++) {If (father [J] & in [J] = 0) {TMP = J; break;} If (! TMP) {puts ("0"); flag = true; return;} int pre = Father [TMP]; In [pre] --; father [TMP] = 0; t-= nn [TMP]; NN [pre] + = nn [TMP]; If (T <0) {puts ("0"); flag = true; return ;}} void dp (Int & N, Int & T) {DP [0] = 1; // do not get for (INT I = 1; I <= N; I ++) {If (NN [I]> T) continue; For (Int J = 0; j + NN [I] <= T; j ++) DP [J + NN [I] = (DP [J + NN [I] + dp [J]) % mod ;}} void output (Int & T) {printf ("% i64d \ n", DP [T]);} int main () {int N, Q, T; Init (); input (n, Q, t); CAL (n, Q, T); If (FLAG) return 0; DP (n, T); output (t); Return 0 ;}


Related Article

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.