每笔收入产生的收益是独立的。

计算所有点的收益率,累计。

  1. #define _CRT_SECURE_NO_WARNINGS
  2. #include<iostream>
  3. #include<algorithm>
  4. #include<vector>
  5. using namespace std;
  6.  
  7. struct dd{
  8. int d, e;
  9. }ndd[];
  10. struct ddd{
  11. int s, f, r;
  12. }mddd[];
  13. bool dddcomp(ddd a, ddd b)
  14. {
  15. return a.s < b.s;
  16. }
  17. int rate[];
  18.  
  19. int max(int a, int b)
  20. {
  21. return a>b ? a : b;
  22. }
  23. int main()
  24. {
  25. int t, n, m;
  26. scanf("%d", &t);
  27. for (int w = ; w <= t; ++w){
  28. memset(rate, , sizeof(rate));
  29. scanf("%d %d", &n, &m);
  30. for (int i = ; i < n; ++i)
  31. scanf("%d %d", &ndd[i].d, &ndd[i].e);
  32. for (int i = ; i < m; ++i)
  33. scanf("%d %d %d", &mddd[i].s, &mddd[i].f, &mddd[i].r);
  34. sort(mddd, mddd + m, dddcomp); //读取数据并排序
  35. //求rate[],rate[i]=max(rate[i+1],rate[j]+r[i-j]),只需考虑 r[i-j]存在的情况
  36. int pos = m - ;
  37. for (int i = mddd[m - ].s; i >= mddd[].s; --i){
  38. int mx = rate[i + ];
  39. while (pos >= && i == mddd[pos].s){
  40. mx = max(mx, mddd[pos].r + rate[mddd[pos].f]);
  41. --pos;
  42. }
  43. rate[i] = mx;
  44. }
  45. for (int i = mddd[].s - ; i >= ; --i)
  46. rate[i] = rate[i + ];
  47. //分别计算收入的收益
  48. long long sum = ;
  49. for (int i = ; i < n; ++i){
  50. sum += rate[ndd[i].d] * ndd[i].e;
  51. }
  52. printf("Case #%d:\n%.2lf\n", w, (double)sum / 100.0);
  53. }
  54. }

Best Financing(HD4833)的更多相关文章

  1. HDU 4833 Best Financing(DP)(2014年百度之星程序设计大赛 - 初赛(第二轮))

    Problem Description 小A想通过合理投资银行理财产品达到收益最大化.已知小A在未来一段时间中的收入情况,描述为两个长度为n的整数数组dates和earnings,表示在第dates[ ...

  2. HDU 4833 Best Financing (DP)

    Best Financing Time Limit: 20000/10000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) ...

  3. hdu4833 Best Financing(DP)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4833 这道题目关键的思想是从后往前dp,dp[i]表示在第i处投资xi能获得的最大收益,其中xi表示从 ...

  4. Translate Exercises(4)

    周五翻译课记录. ---------------------------------- (1)and it is imagined by many that the operations of the ...

  5. (原创)北美信用卡(Credit Card)个人使用心得与总结(个人理财版) [精华]

    http://forum.chasedream.com/thread-766972-1-1.html 本人2010年 8月F1 二度来美,现在credit score 在724-728之间浮动,最高的 ...

  6. Angular2入门系列教程7-HTTP(一)-使用Angular2自带的http进行网络请求

    上一篇:Angular2入门系列教程6-路由(二)-使用多层级路由并在在路由中传递复杂参数 感觉这篇不是很好写,因为涉及到网络请求,如果采用真实的网络请求,这个例子大家拿到手估计还要自己写一个web ...

  7. Angular2学习笔记(1)

    Angular2学习笔记(1) 1. 写在前面 之前基于Electron写过一个Markdown编辑器.就其功能而言,主要功能已经实现,一些小的不影响使用的功能由于时间关系还没有完成:但就代码而言,之 ...

  8. ASP.NET Core 之 Identity 入门(一)

    前言 在 ASP.NET Core 中,仍然沿用了 ASP.NET里面的 Identity 组件库,负责对用户的身份进行认证,总体来说的话,没有MVC 5 里面那么复杂,因为在MVC 5里面引入了OW ...

  9. ABP入门系列(1)——学习Abp框架之实操演练

    作为.Net工地搬砖长工一名,一直致力于挖坑(Bug)填坑(Debug),但技术却不见长进.也曾热情于新技术的学习,憧憬过成为技术大拿.从前端到后端,从bootstrap到javascript,从py ...

随机推荐

  1. [Math]Sqrt(x)

    Total Accepted: 75767 Total Submissions: 314003 Difficulty: Medium Implement int sqrt(int x). Comput ...

  2. CDZSC_2015寒假新人(1)——基础 e

    Description Julius Caesar lived in a time of danger and intrigue. The hardest situation Caesar ever ...

  3. spring注解注入:<context:component-scan>使用说明

    spring从2.5版本开始支持注解注入,注解注入可以省去很多的xml配置工作.由于注解是写入java代码中的,所以注解注入会失去一定的灵活性,我们要根据需要来选择是否启用注解注入. 在XML中配置了 ...

  4. eclipse 常用的一些设置

    1.行长度设置 http://blog.csdn.net/janronehoo/article/details/10047937 2.字体 windows -> preference -> ...

  5. TComponent与String的转换(得到控件的DFM格式的描述)

    现看下面这两个方法,把一个TComponent做成String,再就是把String转成TComponent function ComponentToStringProc(Component: TCo ...

  6. android HttpGet 另开线程获取网络数据问题

    android跨线程通讯可以使用android.os.Handler-android.os.Message这两类对象完成. public static void getResultForHttpGet ...

  7. java中HashSet实现(转)

    hashset底层的数据结构是hash表,hash表实现方式采用数组+链表,数组类型为HashNode,每个数组元素为链表的头指针,链表中存储经过hash函数散列后冲突的元素,数组的长度为26 has ...

  8. stl入门--reverse函数

    #include<iostream> #include<algorithm>          using namespace std; int main() {     ch ...

  9. linux 启动 oracle数据库

    第一步:切换到oracle用户 su - oracle 第二步:启动oracle数据库监听 lsnrctl start 第三步:输入下方命令,出现:sql> sqlplus /nolog 第四步 ...

  10. [笔记] /etc/init.d/ 下脚本的通用结构

    http://sunxiaqw.blog.163.com/blog/static/99065438201111715813443/ 下面以 named 为例 : #!/bin/bash # # nam ...