Codeforces Round #433 (Div. 1) D. Michael and Charging Stations(dp)

题目链接:Codeforces Round #433 (Div. 1) D. Michael and Charging Stations

题意:

一个人每天要加油,1种为1000,1种为2000,如果付全额,会得到10%的回扣放在卡上。

如果卡上有剩余的回扣,可以拿来抵现金。问n天最少需要花多少钱。

题解:

很直观的一个dp就是考虑dp[i][j],表示第i天卡上剩余回扣为j的最小花费。

将所有的数除以100后,j其实是小于40的,严格的说是小于30,官方题解有个证明。

因为卡上不可能积累很多的钱,积累很多,显然会提前拿去抵现金。

所以把j限制在40以内就行了。

然后用滚动数组滚一下,状态转移方程看代码

 1 #include<bits/stdc++.h>
 2 #define F(i,a,b) for(int i=a;i<=b;++i)
 3 using namespace std;
 4
 5 const int N=3e5+7,inf=1e9+7;
 6 int a[N],dp[2][50],now,n;
 7
 8 void gmin(int &a,int b){if(a>b)a=b;}
 9
10 int main()
11 {
12     scanf("%d",&n);
13     F(i,1,n)scanf("%d",a+i),a[i]/=100;
14     now=0;F(i,1,40)dp[now][i]=inf;
15     F(i,1,n)
16     {
17         now^=1;F(j,0,40)dp[now][j]=inf;
18         F(j,0,40)
19         {
20             gmin(dp[now][j+a[i]/10],dp[now^1][j]+a[i]);//付全额
21             gmin(dp[now][j-a[i]+max(a[i]-j,0)],dp[now^1][j]+max(a[i]-j,0));//抵现金
22         }
23     }
24     int ans=inf;
25     F(i,0,40)gmin(ans,dp[now][i]);
26     printf("%d00\n",ans);
27     return 0;
28 }

时间: 2024-10-12 01:49:44

Codeforces Round #433 (Div. 1) D. Michael and Charging Stations(dp)的相关文章

Codeforces Round #433 (Div. 2)

题目链接:Codeforces Round #433 (Div. 2) codeforces 854 A. Fraction[水] 题意:已知分子与分母的和,求分子小于分母的 最大的最简分数. 1 #include <iostream> 2 #include <cstdio> 3 #include <cstring> 4 #include <algorithm> 5 using namespace std; 6 int gcd(int a,int b){re

Codeforces Round #267 (Div. 2) C. George and Job(DP)补题

Codeforces Round #267 (Div. 2) C. George and Job题目链接请点击~ The new ITone 6 has been released recently and George got really keen to buy it. Unfortunately, he didn't have enough money, so George was going to work as a programmer. Now he faced the follow

Codeforces Round #419 (Div. 2) E. Karen and Supermarket(树形DP)

题目链接:Codeforces Round #419 (Div. 2) E. Karen and Supermarket 题意: 有n件物品,每个物品有一个价格,和一个使用优惠券的价格,不过这个优惠券有一个限制,必须要在第x个使用后才可以使用.现在有m的钱,问最多能买多少个物品. 题解: 每个优惠券都只与一个券有关,所以根据这个关系就可以构成一棵树. 考虑树形dp,dp[i][j][k(0|1)]表示第i个节点所构成的子树中买了j个物品,使用优惠券和不使用优惠券的最少钱. 转移方程看代码详细解释

Codeforces Round #433 (Div. 2, based on Olympiad of Metropolises) D

Country of Metropolia is holding Olympiad of Metrpolises soon. It mean that all jury members of the olympiad should meet together in Metropolis (the capital of the country) for the problem preparation process. There are n + 1 cities consecutively num

Codeforces Round #433 (Div. 2, based on Olympiad of Metropolises) A. Fraction

题意:2个数A,B,A+B==n,并且A<B,问最大的A/B是多少,A与B互质 1 #include<bits/stdc++.h> 2 using namespace std; 3 const int N=1e5+100; 4 typedef long long ll; 5 6 7 int main(){ 8 int n; 9 cin>>n; 10 for(int i=n/2;i>=1;i--){ 11 int y=n-i; 12 if(__gcd(i,y)==1){

Codeforces Round #433 (Div. 2, based on Olympiad of Metropolises) C. Planning

题意:给出每个航班花费和顺序,求新顺序使得花费最少 思路:肯定是花费最大的先决定,二分一下 1 #include<bits/stdc++.h> 2 using namespace std; 3 const int N=1e5+100; 4 typedef long long ll; 5 6 struct node{ 7 ll x; 8 int id; 9 ll yy; 10 }a[300004]; 11 bool cmp(node p,node q){ 12 return p.x>q.x

Codeforces Round #433 (Div. 2, based on Olympiad of Metropolises) B. Maxim Buys an Apartment

题意:有n个房子,k个有人住,问最少有多个,最多有多少个好的房子,好的房子定义:周围最少有一个房子有人住 思路:我们可以知道一个住了人的房子他最多产生2个好的房子(左右)所以判断k*3是否>=n 1 #include<bits/stdc++.h> 2 using namespace std; 3 const int N=1e5+100; 4 typedef long long ll; 5 6 7 int main(){ 8 ll n,k; 9 cin>>n>>k;

Codeforces Round #433 (Div. 2, based on Olympiad of Metropolises) A

Petya is a big fan of mathematics, especially its part related to fractions. Recently he learned that a fraction  is called proper iff its numerator is smaller than its denominator (a < b) and that the fraction is called irreducible if its numerator

Codeforces Round #396 (Div. 2)C. Mahmoud and a Message(dp)

题目链接:http://codeforces.com/problemset/problem/766/C 题意:给你一组小写字母组成的字符串,和26个数字,分别对应26位小写字母能够存在的字符串的最大长度. 要求:①:求出最多的划分方案 ②:求出分配方案中,最长的子串长度 ③:求出分配方案中,最少分成的子串数 思路:关于①:设置dp[i],dp[i]表示在第i个字符后面有一个横杠的方案数,从第i个往前枚举前一个横杠的位置j. 举个例子,有子串abc,当横杠断在a处,有一种方案,dp[1]=1:当横