zoukankan      html  css  js  c++  java
  • uva 6952 Cent Savings dp

    Cent Savings

    Time Limit: 20 Sec  Memory Limit: 256 MB

    题目连接

    http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=116998

    Description

    To host a regional contest like NWERC a lot of preparation is necessary: organizing rooms and computers, making a good problem set, inviting contestants, designing T-shirts, booking hotel rooms and so on. I am responsible for going shopping in the supermarket.

    When I get to the cash register, I put all my n items on the conveyor belt and wait until all the other customers in the queue in front of me are served. While waiting, I realize that this supermarket recently started to round the total price of a purchase to the nearest multiple of 10 cents (with 5 cents being rounded upwards). For example, 94 cents are rounded to 90 cents, while 95 are rounded to 100.

    It is possible to divide my purchase into groups and to pay for the parts separately. I managed to find d dividers to divide my purchase in up to d+1 groups. I wonder where to place the dividers to minimize the total cost of my purchase. As I am running out of time, I do not want to rearrange items on the belt.

    Input

    The input consists of:

        one line with two integers n (1≤n≤2000) and d (1≤d≤20), the number of items and the number of available dividers;
        one line with n integers p1,… pn (1≤pi≤10000 for 1≤i≤n), the prices of the items in cents. The prices are given in the same order as the items appear on the belt.


    Output

    Output the minimum amount of money needed to buy all the items, using up to d dividers.

    Sample Input

    5 1
    13 21 55 60 42

    Sample Output

    190

    HINT

    题意

     这个商店交款方式是4舍5入的,然后你可以把你的商品分成d堆交钱

    然后问你最少交多少钱

    题解:

    dp题呀

    就相当于有n-1个空,插d个板子

    那么我们就可以DP解决他,dp[i][j]表示前i个空插了j个板子后的最小值

    代码:

    //qscqesze
    #include <cstdio>
    #include <cmath>
    #include <cstring>
    #include <ctime>
    #include <iostream>
    #include <algorithm>
    #include <set>
    #include <vector>
    #include <sstream>
    #include <queue>
    #include <typeinfo>
    #include <fstream>
    #include <map>
    #include <stack>
    typedef long long ll;
    using namespace std;
    //freopen("D.in","r",stdin);
    //freopen("D.out","w",stdout);
    #define sspeed ios_base::sync_with_stdio(0);cin.tie(0)
    #define maxn 200001
    #define mod 10007
    #define eps 1e-9
    int Num;
    char CH[20];
    //const int inf=0x7fffffff;   //нчоч╢С
    const int inf=0x3f3f3f3f;
    /*
    
    inline void P(int x)
    {
        Num=0;if(!x){putchar('0');puts("");return;}
        while(x>0)CH[++Num]=x%10,x/=10;
        while(Num)putchar(CH[Num--]+48);
        puts("");
    }
    */
    inline ll read()
    {
        int x=0,f=1;char ch=getchar();
        while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
        while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
        return x*f;
    }
    inline void P(int x)
    {
        Num=0;if(!x){putchar('0');puts("");return;}
        while(x>0)CH[++Num]=x%10,x/=10;
        while(Num)putchar(CH[Num--]+48);
        puts("");
    }
    //**************************************************************************************
    
    
    int a[2010];
    ll dp[2010][30];
    ll cal(ll x)
    {
        if(x%10>=5)
            x+=10;
        x-=x%10;
        return x;
    }
    int main()
    {
        int n,d;
        scanf("%d%d",&n,&d);
        for(int i=1;i<=n;i++)
            a[i]=read();
        for(int i=1;i<=n-1;i++)
        {
            for(int j=0;j<=d;j++)
            {
                if(j==0)
                    dp[i][j]+=dp[i-1][j]+a[i];
                else
                    dp[i][j]=min(dp[i-1][j]+a[i],cal(dp[i-1][j-1]+a[i]));
            }
        }
        ll ans=inf;
        for(int j=0;j<=d;j++)
            ans=min(cal(dp[n-1][j]+a[n]),ans);
        cout<<ans<<endl;
    }
  • 相关阅读:
    「笔记」高斯消元
    函数库
    数学公式杂记
    CF1290E Cartesian Tree
    洛谷 P4027 [NOI2007] 货币兑换
    审计ThinkCMF框架任意内容包含漏洞与复现
    PHP代码审计笔记(基础篇)--命令执行漏洞
    某校园缴费平台通用0day偶然发现之路
    【转】教育src挖掘经验
    近期学习文章的整理(超级干货总结分享)
  • 原文地址:https://www.cnblogs.com/qscqesze/p/4510312.html
Copyright © 2011-2022 走看看