2017中国大学生程序设计竞赛 - 女生专场(dp)

Building Shops 
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others) 
Total Submission(s): 701 Accepted Submission(s): 265

Problem Description 
HDU’s n classrooms are on a line ,which can be considered as a number line. Each classroom has a coordinate. Now Little Q wants to build several candy shops in these n classrooms.

The total cost consists of two parts. Building a candy shop at classroom i would have some cost ci. For every classroom P without any candy shop, then the distance between P and the rightmost classroom with a candy shop on P’s left side would be included in the cost too. Obviously, if there is a classroom without any candy shop, there must be a candy shop on its left side.

Now Little Q wants to know how to build the candy shops with the minimal cost. Please write a program to help him.

Input 
The input contains several test cases, no more than 10 test cases. 
In each test case, the first line contains an integer n(1≤n≤3000), denoting the number of the classrooms. 
In the following n lines, each line contains two integers xi,ci(?109≤xi,ci≤109), denoting the coordinate of the i-th classroom and the cost of building a candy shop in it. 
There are no two classrooms having same coordinate.

Output 
For each test case, print a single line containing an integer, denoting the minimal cost.

Sample Input 

1 2 
2 3 
3 4 

1 7 
3 1 
5 10 
6 1

Sample Output 

11

Source 
2017中国大学生程序设计竞赛 - 女生专场

题意: 
有n个教室,现在想在这n个教室中建一些超市,问你最少费用为多少? 
费用分为两种: 
1:在第i个教室建超市,费用因为ci 
2:没有建超市的教室的费用为它和它左边最接近的超市的坐标之间的距离

#include <iostream>
#include<cstring>
#include<string>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<deque>
#define ll long long
#define inf 0x3f3f3f3f
using namespace std;
struct node
{
    ll x;
    ll c;
}a[3005];
bool cmp(node x,node y)
{
    return x.x<y.x;
}
ll dp[3005];
//dp[i]表示只考虑前i个教室 的最优解
ll dp2[3005];
//dp2[i]表示 第i个固定条件下,前i个的最优解
ll s[3005];
int main()
{
    int n;
    while(~scanf("%d",&n))
    {
        for(int i=1;i<=n;i++)
        {
            scanf("%lld %lld",&a[i].x,&a[i].c);

        }
        sort(a+1,a+n+1,cmp);
        memset(dp,inf,sizeof(dp));
        memset(dp2,inf,sizeof(dp2));
        memset(s,0,sizeof(s));
        dp[0]=0;
        dp[1]=dp2[1]=a[1].c;
        int pp=a[1].x;
        for(int i=1;i<=n;i++)
        {
            a[i].x-=pp;
            s[i]=a[i].x+s[i-1];
        }
        for(int i=1;i<=n;i++)
        {
            dp2[i]=dp[i-1]+a[i].c;
            //第i个固定条件下,前i个的最优解
            for(int j=1;j<=i;j++)
            {
                dp[i]=min(dp[i],dp2[j]+s[i]-s[j]-(i-j)*a[j].x);
            }
        }
        printf("%lld\n",dp[n]);
    }
    return 0;
}

Building Shops

Time
Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/131072 K
(Java/Others)
Total Submission(s): 2728    Accepted Submission(s):
936

Problem Description

HDU’s n

classrooms are on a line ,which can be considered as a number line. Each
classroom has a coordinate. Now Little Q wants to build several candy shops in
these n

classrooms.

The total cost consists of two parts. Building a candy shop
at classroom i

would have some cost ci

. For every classroom P

without any candy shop, then the distance between P

and the rightmost classroom with a candy shop on P

‘s left side would be included in the cost too. Obviously, if there is a
classroom without any candy shop, there must be a candy shop on its left
side.

Now Little Q wants to know how to build the candy shops with the
minimal cost. Please write a program to help him.

Input

The input contains several test cases, no more than 10
test cases.
In each test case, the first line contains an integer n(1≤n≤3000)

, denoting the number of the classrooms.
In the following n

lines, each line contains two integers xi,ci(?109≤xi,ci≤109)

, denoting the coordinate of the i

-th classroom and the cost of building a candy shop in it.
There are no two
classrooms having same coordinate.

Output

For each test case, print a single line containing an
integer, denoting the minimal cost.

Sample Input

3
1 2
2 3
3 4
4
1 7
3 1
5 10
6 1

Sample Output

5
11

Source

2017中国大学生程序设计竞赛
- 女生专场

Recommend

jiangzijing2015   |   We have carefully selected
several similar problems for you:  6286 6285 6284 6283 6282

原文地址:https://www.cnblogs.com/caiyishuai/p/9073653.html

时间: 2024-12-23 21:37:20

2017中国大学生程序设计竞赛 - 女生专场(dp)的相关文章

2017中国大学生程序设计竞赛 - 女生专场 Happy Necklace(递推+矩阵快速幂)

Happy Necklace Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)Total Submission(s): 1146    Accepted Submission(s): 491 Problem Description Little Q wants to buy a necklace for his girlfriend. Necklaces are single

2017中国大学生程序设计竞赛 - 女生专场 Deleting Edges(思维+最短路)

Deleting Edges Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)Total Submission(s): 567    Accepted Submission(s): 210 Problem Description Little Q is crazy about graph theory, and now he creates a game about grap

2017中国大学生程序设计竞赛 - 女生专场 1002 dp

Building Shops Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)Total Submission(s): 0    Accepted Submission(s): 0 Problem Description HDU’s n classrooms are on a line ,which can be considered as a number line. Ea

2017中国大学生程序设计竞赛 - 女生专场(重现)

A.Automatic Judge(模拟) Problem Description Welcome to HDU to take part in the second CCPC girls’ competition!A new automatic judge system is used for this competition. During the five-hour contest time, you can submit your code to the system, then the

&quot;巴卡斯杯&quot; 中国大学生程序设计竞赛 - 女生专场(重现)解题思路

此文章可以使用目录功能哟↑(点击上方[+]) 经过这么一次女生赛,告诉我们千万不要小瞧女生,不然会死得很惨,orz... 链接→"巴卡斯杯" 中国大学生程序设计竞赛 - 女生专场(重现)  Problem 1001 Solving Order Accept: 0    Submit: 0 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit : 32768/32768 K (Java/Others)  Problem Descri

HDU 6024(中国大学生程序设计竞赛女生专场1002)

这是CCPC女生专场的一道dp题.大佬们都说它简单,我并没有感到它有多简单. 先说一下题意:在一条直线上,有n个教室,现在我要在这些教室里从左到右地建设一些作为糖果屋,每个教室都有自己的坐标xi 和建造糖果屋的费用ci , 如果在这里建造一个糖果屋,那么花费ci ,如果不建造糖果屋,则花费是当前教室的坐标与左边最靠近当前教室的糖果屋坐标之差,问最小花费. 一看这是个求最优解的问题,应该明白这是个dp问题,现在来考虑该问题状态的定义: 当我建设到第i个教室的时候,我有两种选择,建糖果屋或者不建糖果

&quot;巴卡斯杯&quot; 中国大学生程序设计竞赛 - 女生专场

Combine String #include<cstdio> #include<cstring> #include<iostream> #include<algorithm> #include<cmath> #include<queue> #include<vector> #include<map> using namespace std; typedef unsigned long long LL; #de

&quot;字节跳动杯&quot;2018中国大学生程序设计竞赛-女生专场 Solution

A - 口算训练 题意:询问 $[L, R]$区间内 的所有数的乘积是否是D的倍数 思路:考虑分解质因数 显然,一个数$x > \sqrt{x} 的质因子只有一个$ 那么我们考虑将小于$\sqrt {x}$ 的质因子用线段树维护 其他质因子用vector 维护存在性 1 #include <bits/stdc++.h> 2 using namespace std; 3 4 #define N 100010 5 #define block 317 6 vector <int>

2017中国大学生程序设计竞赛 - 网络选拔赛 HDU 6154 CaoHaha&#39;s staff 思维

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6154 题意:在笛卡尔坐标系下,画一个面积至少为  n 的简单多边形,每次只能画一条边或者一个格子的对角线,问至少要画几条. 解法:如果一个斜着的矩形长宽分别是 a,b,那么它的面积是 2ab.最优解肯定是离 sqrt(n/2)很近的位置.想想 n=5 时答案为什么是7 然后在那个小范围内枚举一下就好了.我给一张做题时画的图 #include <bits/stdc++.h> using namesp