POJ 1276 Cash Machine

Source: Internet
Author: User

Test instructions: give you the value of n denominations, tell you the value of each face and the number of dollars, ask can make up the largest amount of money is not more than M.

Solution: Multiple backpacks. I think direct multi-pack Turn 01 should be t ... And I'm too lazy to do it in binary ... With the POJ1472 of the idea of doing a bit ...

Code:

#include <stdio.h> #include <iostream> #include <algorithm> #include <string> #include < string.h> #include <math.h> #include <limits.h> #include <time.h> #include <stdlib.h># include<map> #include <queue> #include <set> #include <stack> #include <vector> #define LL Long longusing namespace Std;bool dp[100005];int used[100005];struct node{int val, num;}    Money[15];int Main () {int n, m;        while (~SCANF ("%d%d", &m, &n)) {memset (DP, 0, sizeof DP);        int ans = 0;        for (int i = 1; I <= n; i++) scanf ("%d%d", &money[i].num, &money[i].val);        Dp[0] = true;            for (int i = 1; I <= n; i++) {memset (used, 0, sizeof used); for (int j = 1; j <= M; j + +) {if (!dp[j] && J >= Money[i].val && Dp[j-mon Ey[i].val] && Used[j-money[i].val] < Money[i].num) {ans = mAx (ans, j);                    DP[J] = true;                USED[J] = Used[j-money[i].val] + 1;    }}} printf ("%d\n", ans); } return 0;}

  

POJ 1276 Cash Machine

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.