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;
    }
  • 相关阅读:
    linux下安装EJBCA 搭建私有CA服务器
    PHP 设计模式之观察者模式
    PHP 设计模式之三种工厂模式
    PHP 设计模式之单例模式
    解決 VMware Workstation 与 Device/Credential Guard 不相容,无法启动虚拟机的问题
    Mac 外接鼠标不好用?这个软件解决你的痛点
    PHP Trait 解决 PHP 单继承问题
    Wordpress 添加图片点击放大效果
    PHP 实现 WebSocket 协议
    Web 网页直接打开 Windows 软件
  • 原文地址:https://www.cnblogs.com/qscqesze/p/4510312.html
Copyright © 2011-2022 走看看