HDU 5410 CRB and His Birthday
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5410
She went to the nearest shop with M Won(currency unit).
At the shop, there are N kinds of presents.
It costs Wi Won to buy one present of i-th kind. (So it costs k × Wi Won to buy k of them.)
But as the counter of the shop is her friend, the counter will give Ai × x + Bi candies if she buys x(x>0) presents of i-th kind.
She wants to receive maximum candies. Your task is to help her.
1 ≤ T ≤ 20
1 ≤ M ≤ 2000
1 ≤ N ≤ 1000
0 ≤ Ai, Bi ≤ 2000
1 ≤ Wi ≤ 2000
The first line contains two integers M and N.
Then N lines follow, i-th line contains three space separated integers Wi, Ai and Bi.
CRB's mom buys 10 presents of first kind, and receives 2 × 10 + 1 = 21 candies.
1 #include <iostream> 2 #include <cstring> 3 using namespace std; 4 5 int ma(int a,int b) 6 { 7 if (a>b) 8 return a; 9 else 10 return b; 11 } 12 int main() 13 { 14 int ans[12000],v,a[1100],b[1100],c[1100],n,m,T; 15 cin>>T; 16 while (T--) 17 { 18 cin>>v>>m; 19 for (int i=1;i<=m;i++) 20 cin>>c[i]>>a[i]>>b[i]; 21 memset(ans,0,sizeof(ans)); 22 for (int i=1;i<=m;i++)//处理第一阶段,0/1背包 23 { 24 for (int j=v;j>=c[i];j--) 25 { 26 ans[j]=ma(ans[j],ans[j-c[i]]+a[i]+b[i]); 27 } 28 } 29 for (int i=1;i<=m;i++)//处理第二阶段,完全背包。 30 { 31 for (int j=c[i];j<=v;j++) 32 { 33 ans[j]=ma(ans[j],ans[j-c[i]]+a[i]); 34 } 35 } 36 cout <<ans[v]<<endl; 37 } 38 return 0; 39 }
View Code
转载于:https://www.cnblogs.com/arno-my-boke/p/4763998.html
HDU 5410 CRB and His Birthday相关推荐
- HDU 5410 CRB and His Birthday ——(完全背包变形)
对于每个物品,如果购买,价值为A[i]*x+B[i]的背包问题. 先写了一发是WA的= =.代码如下: 1 #include <stdio.h> 2 #include <algori ...
- hdu 5410(背包问题变形)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5410 解题思路:令dp[i][j][0]表示前i种物品,共j钱,不买第i种物品所能买到的最大值.dp[ ...
- HDU - 5411 CRB and Puzzle 矩阵快速幂
HDU - 5411 考虑直接dp会T, 用矩阵优化一下就好了. #include<bits/stdc++.h> #define LL long long #define LD long ...
- hdu 5411 CRB and Puzzle(矩阵快速幂)
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5411 解题思路: 题目大意: 给定n个点 常数m 下面n行第i行第一个数字表示i点的出边数,后面给出 ...
- HDU 5411 CRB and Puzzle (2015年多校比赛第10场)
1.题目描写叙述:点击打开链接 2.解题思路:本题实际是是已知一张无向图.问长度小于等于m的路径一共同拥有多少条. 能够通过建立转移矩阵利用矩阵高速幂解决.当中,转移矩阵就是输入时候的邻接矩阵,同一时 ...
- hdu 5411 CRB and Puzzle 矩阵高速幂
链接 题解链接:http://www.cygmasot.com/index.php/2015/08/20/hdu_5411/ 给定n个点 常数m 以下n行第i行第一个数字表示i点的出边数.后面给出这些 ...
- hdu 5411 CRB and Puzzle
Sample Input 1 3 2 1 2 1 3 0 Sample Output 6 Hint possible patterns are ∅, 1, 2, 3, 1→2, 2→3 解释样例: 第 ...
- 【矩阵快速幂】 HDU 5411 CRB and Puzzle 等比
点击打开链接 题意显然是 求 A+A^2+A^3+....+A^m 这就是经典题目 矩阵乘法十种经典题目 递归解决 后半部分提取 A^(m/2) 该题再特判下 m==1的时候 #include < ...
- 小算法小心情:背包问题就是陪你看花开向阳
一开始接触背包问题,总会有些困扰,无法完全理解,或者说不断地忘记所谓的公式,特神说分享,可以让许多人少走弯路,我觉得颇有道理,其实我想做的,只是努力让让算法变得看上去简单易懂一些,因为我也曾是个迷惘无 ...
最新文章
- 3168串口java_电子称串口读取数据(转)
- 《TCP/IP详解 卷1:协议》第4章 ARP:地址解析协议
- python调用动态库出现error193_切换到64位时使用Python Winerror 193
- 单点登录(SSO)—简介 1
- css 相对定位 ie7问题
- python调用opengl_Python运行OpenGL示例
- Concurrent HTTP connections in Node.js
- java外部类_Java里什么叫内部类什么叫外部类
- 强健程序员体魄————减脂原理
- 狗狗币暴涨暴跌?数据分析师带你走进它的前世今生!
- 运营九年,这款音乐手游宣布停服!将从应用商店下架...
- 【hortonworks/registries】Parameter Schema name is null
- 2008年9月三级网络技术考试试卷 参考答案1
- PHP学习笔记01——基础语法
- Python入门--字符串的分割操作,split,rsplit
- VMProtect修复导入表的插件
- Mac版 QQ防撤回插件
- swift 隐藏状态栏_Swift - 动态改变状态栏statusBar文字颜色(preferredStatusBarStyle无效问题)...
- sony xz2c android升9,坐稳放宽,索尼Xperia XZ2/XZ2 Compact安卓9 Pie已开始逐步推送
- Android 常用开源库总结
热门文章
- python爬取flash数据_爬取flash数据
- faster rcnn resnet_张航、李沐等人提出ResNet最强改进版:性能提高3%,参数不增
- 数值分析matlab实验报告,数值分析第一次作业matlab实验报告.doc
- mysql的储存原理_mysql储存原理
- 项目管理实践之版本控制工具SVN
- C语言:输入四个数a,b,c,d,将这四个数由小到大排序
- php数组array_filter,php数组array_filter()函数和array_slice()函数
- 图的存储结构之邻接表
- spark 持久化机制入门
- 信息存储服务公司Everlaw获810万美金注资