HDU - 1300 简单DP
题意:买珠子的方案有两种,要么单独买,价钱为该种类数量+10乘上相应价格,要么多个种类的数量相加再+10乘上相应最高贵的价格买
坑点:排序会WA,喵喵喵?
为什么连续取就是dp的可行方案?我猜的..
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<string>
#include<vector>
#include<stack>
#include<queue>
#include<set>
#include<map>
#define rep(i,j,k) for(register int i=j;i<=k;i++)
#define rrep(i,j,k) for(register int i=j;i>=k;i--)
#define erep(i,u) for(register int i=head[u];~i;i=nxt[i])
#define iin(a) scanf("%d",&a)
#define lin(a) scanf("%lld",&a)
#define din(a) scanf("%lf",&a)
#define s0(a) scanf("%s",a)
#define s1(a) scanf("%s",a+1)
#define print(a) printf("%lld",(ll)a)
#define enter putchar('\n')
#define blank putchar(' ')
#define println(a) printf("%lld\n",(ll)a)
#define IOS ios::sync_with_stdio(0)
using namespace std;
const int maxn = 1e5+11;
const int oo = 0x3f3f3f3f;
const double eps = 1e-7;
typedef long long ll;
ll read()
{
ll x=0,f=1;register 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;
}
struct A{
int num,price;
}a[maxn];
bool cmp(A a,A b){
return a.price<b.price;
}
ll dp[maxn],sum[maxn];
int main(){
int T=read();
while(T--){
int n=read();
rep(i,1,n){
a[i].num=read();
a[i].price=read();
}
// sort(a+1,a+1+n,cmp);
rep(i,1,n) sum[i]=sum[i-1]+a[i].num;
rep(i,1,n) dp[i]=(sum[i]+10)*a[i].price;
rep(i,2,n){
rep(j,1,i-1){
dp[i]=min(dp[i],dp[j]+(sum[i]-sum[j]+10)*a[i].price);
}
}
println(dp[n]);
}
return 0;
}
HDU - 1300 简单DP的更多相关文章
- HDU 1087 简单dp,求递增子序列使和最大
Super Jumping! Jumping! Jumping! Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 ...
- hdu 2471 简单DP
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2571 简单dp, dp[n][m] +=( dp[n-1][m],dp[n][m-1],d[i][k ...
- D - Pearls HDU - 1300 斜率dp+二分
D - Pearls HDU - 1300 这个题目也是一个比较裸的斜率dp,依照之前可以推一下这个公式,这个很好推 这个注意题目已经按照价格升序排列序,所以还是前缀和还是单调的. sum[i] 表示 ...
- HDU 1708 简单dp问题 Fibonacci String
Fibonacci String Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) ...
- hdu 1257 && hdu 1789(简单DP或贪心)
第一题;http://acm.hdu.edu.cn/showproblem.php?pid=1257 贪心与dp傻傻分不清楚,把每一个系统的最小值存起来比较 #include<cstdio> ...
- [hdu 1398]简单dp
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1398 看到网上的题解都是说母函数……为什么我觉得就是一个dp就好了,dp[i][j]表示只用前i种硬币 ...
- Max Sum (hdu 1003 简单DP水过)
Max Sum Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Su ...
- hdu 2845简单dp
/*递推公式dp[i]=MAX(dp[i-1],dp[i-2]+a[j])*/ #include<stdio.h> #include<string.h> #define N 2 ...
- Tickets HDU - 1260 简单dp
#include<iostream> using namespace std; const int N=1e5; int T,n; int a[N],b[N]; int dp[N]; in ...
随机推荐
- #Pragma Pack与内存分配
博客转载自:https://blog.csdn.net/mylinx/article/details/7007309 #pragma pack(n) 解释一: 每个特定平台上的编译器都有自己的默认“对 ...
- blockchain notes
1. IBM blockchain platform https://www.ibm.com/blockchain/platform/ 2. 开源项目hyperledger https://hyper ...
- list 的扩展
数据挖掘中会遇到添加多个新的特征s,对一个feature = list()来说, 除了可以用 feature.append('xx') # 在尾部添加一个特征 feature.extend(['xx' ...
- 符合mvc思维的分页思想
.Model Student.cs namespace WebApplication14.Models { public class Student { public int Id { get; se ...
- hdu 2206 IP的计算(最全的注意事项)
注意: 1.非法字符(包括空格) 如下都是错的 A.145.124.4 192.168.18 123(用scanf输入的话,则接收的是:192.168.18) 2.'.'有且仅有3个,且不能连续出现, ...
- Linux下chmod 777 修改权限
在linux操作系统下,使用shell命令来操作: 关于权限的问题用chmod命令来修改权限 -rw-r-r-- 1 root root 可参考:http://zhidao.baidu.com/lin ...
- js实现选项卡切换
<!DOCTYPE html><html><head lang="en"> <meta charset="UTF-8" ...
- Python基础-2
目录: 1.列表.元组操作 2.字符串操作 3.字典操作 4.集合操作 5.文件操作 6.字符编码与转码 一.列表.元组操作 定义列表 names = ['Freeman',"Jack&qu ...
- 基本滤波算法比较 (转载http://blog.sina.com.cn/s/blog_69f2aa5a01014du5.html)
最近在做关于数据采集方面的东西,这就不免涉及到了滤波的算法,在网上找到了关于几种算法的比较. 数字滤波方法有很多种,每种方法有其不同的特点和使用范围.从大的范围可分为3类. 1.克服大脉冲干扰的数字滤 ...
- centos 升级 python
1. 下载python 2.7编译安装 $wget http://www.python.org/ftp/python/2.7.3/Python-2.7.3.tgz $tar zxvf Python-. ...