UVALive-4905 Pro-Test Voting

Source: Internet
Author: User

Test instructions: A person campaigning, spending money canvassing, each community has the corresponding information, according to the formula to calculate the number of votes (rounding) the same time (according to the first community, the most cost, and so on)

Train of thought: even when the result is the same, according to the cost of the former community is more accurate, then obviously we have to push from the forward, according to the idea of the backpack, Dp[i][j] represents the largest number of votes from the community of N-1 to the community of J-k

The other place is to mark the cost of the first I

#include <cstdio> #include <cstring> #include <iostream> #include <algorithm> using namespace
Std

const int MAXN = 110; struct node{int n,ip,r;}
ARR[MAXN];
int DP[MAXN][MAXN],F[MAXN][MAXN];

int n,m;
    int main () {int t = 1;
        while (scanf ("%d%d", &m,&n) && n+m) {memset (dp,0,sizeof (DP));
        memset (F,0,sizeof (f));
        printf ("Case%d:", t++); for (int i = 0; i < n; i++) scanf ("%d%d%d", &arr[i]. N,&arr[i]. Ip,&arr[i].
        R); for (int i = 0; I <=; i++) {Dp[n-1][i] = (arr[n-1]. ip+i/(i+10.1) *arr[n-1]. R)/100*arr[n-1].
            n+0.5;
        F[n-1][i] = i; } for (int i = n-2, i >= 0; i--) for (int j = 0; J <=; J + +) {int Max = 0,max
                K for (int k = 0; k <= J; k++) {int temp = (int) (dp[i+1][j-k]+ (arr[i). ip+k/(k+10.1) *arr[i]. R)/100*arr[i].
                    n+0.5);
   if (temp >= Max) {                     Max = temp;
                    Maxk = k;
                    } Dp[i][j] = Max;
                F[I][J] = maxk;
        }} printf ("%d\n", Dp[0][m]);
        int temp = M,flag = 1;
                for (int i = 0; i < n; i++) {if (flag) {printf ("%d:%d", I,f[i][temp]);
            Flag = 0;
            } else printf ("%d:%d", I,f[i][temp]);
        Temp-= f[i][temp];
    } printf ("\ n");
} 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.