hznu 1136: Investment(01背包与完全背包的区别)

本文探讨了通过购买和出售债券来最大化资本增长的策略。利用不同规模的债券及其年利息,通过最优买卖计划,在指定时间内实现资本最大增值。

John never knew he had a grand-uncle, until he received the notary's letter. He learned that his late grand-uncle had gathered a lot of money, somewhere in South-America, and that John was the only inheritor. John did not need that much money for the moment. But he realized that it would be a good idea to store this capital in a safe place, and have it grow until he decided to retire. The bank convinced him that a certain kind of bond was interesting for him.

This kind of bond has a fixed value, and gives a fixed amount of yearly interest, payed to the owner at the end of each year. The bond has no fixed term. Bonds are available in different sizes. The larger ones usually give a better interest. Soon John realized that the optimal set of bonds to buy was not trivial to figure out. Moreover, after a few years his capital would have grown, and the schedule had to be re-evaluated.

Assume the following bonds are available:

ValueAnnual interest
4000400
3000250

With a capital of 10 000 one could buy two bonds of $4 000, giving a yearly interest of $800. Buying two bonds of $3 000, and one of $4 000 is a better idea, as it gives a yearly interest of $900. After two years the capital has grown to $11 800, and it makes sense to sell a $3 000 one and buy a $4 000 one, so the annual interest grows to $1 050. This is where this story grows unlikely: the bank does not charge for buying and selling bonds. Next year the total sum is $12 850, which allows for three times $4 000, giving a yearly interest of $1 200.

Here is your problem: given an amount to begin with, a number of years, and a set of bonds with their values and interests, find out how big the amount may grow in the given period, using the best schedule for buying and selling bonds.

输入

The first line contains a single positive integer N which is the number of test cases.

The test cases follow.

The first line of a test case contains two positive integers: the amount to start with (at most $1 000 000), and the number of years the capital may grow (at most 40).

The following line contains a single number: the number d (1 <= d <= 10) of available bonds.

The next d lines each contain the description of a bond. The description of a bond consists of two positive integers: the value of the bond, and the yearly interest for that bond. The value of a bond is always a multiple of $1 000. The interest of a bond is never more than 10% of its value.

输出

For each test case, output – on a separate line – the capital at the end of the period, after an optimal schedule of buying and selling.

样例输入

1
10000 4  //1W块钱存4年
2    //两种选择(1年)
4000 400  //4000块钱获利400
3000 250  //3000块钱获利250

样例输出

14050  //最后的获利

for(v=V; v>w[i]; --v)  //逆序推能够保证 f[v-c[i]] 保存的是状态是 f[i-1][v-c[i]] ,也就是每个物品只被使用了一次;顺序的话 f[v-c[i]] 保存的是 f[i][v-c[i]] ,每个物品有可能被使用多次,也就是完全背包问题的解法。

#include<iostream>
#include<algorithm>
#include<string>
#include<string.h>
#include<vector>
#include<cmath>
#include<map>
#include<stdlib.h>
#include<stdio.h>
#define ll long long
using namespace std;
struct node{
	int a,b;
};
int dp[100001];
int main(){
	int t;
	cin>>t;
	while(t--){
		int n,m;
		cin>>n>>m;
		node x[11];
		int g;
		cin>>g;
		for(int i=0;i<g;++i){
			cin>>x[i].a>>x[i].b;
			x[i].a/=1000;
		}
		while(m--){
			memset(dp,0,sizeof(dp));
			for(int i=0;i<g;++i){
				for(int j=x[i].a;j<=n/1000;j++){
				//for(int j=n/1000;j>=x[i].a;--j){
					dp[j]=max(dp[j],dp[j-x[i].a]+x[i].b);
				}
			}
			n+=dp[n/1000];
		}
		cout<<n<<endl;
	}
	return 0;
}


内容概要:本文档是一份关于交换路由配置的学习笔记,系统地介绍了网络设备的远程管理、交换机路由器的核心配置技术。内容涵盖Telnet、SSH、Console三种远程控制方式的配置方法;详细讲解了VLAN划分原理及Access、Trunk、Hybrid端口的工作机制,以及端口镜像、端口汇聚、端口隔离等交换技术;深入解析了STP、MSTP、RSTP生成树协议的作用配置步骤;在路由部分,涵盖了IP地址配置、DHCP服务部署(接口池全局池)、NAT转换(静态动态)、静态路由、RIPOSPF动态路由协议的配置,并介绍了策略路由ACL访问控制列表的应用;最后简要说明了华为防火墙的安全区域划分基本安全策略配置。; 适合人群:具备一定网络基础知识,从事网络工程、运维或相关技术岗位1-3年的技术人员,以及准备参加HCIA/CCNA等认证考试的学习者。; 使用场景及目标:①掌握企业网络中常见的交换路由配置技能,提升实际操作能力;②理解VLAN、STP、OSPF、NAT、ACL等核心技术原理并能独立完成中小型网络搭建调试;③通过命令示例熟悉华为设备CLI配置逻辑,为项目实施故障排查提供参考。; 阅读建议:此笔记以实用配置为主,建议结合模拟器(如eNSP或Packet Tracer)动手实践每一条命令,对照拓扑理解数据流向,重点关注VLAN间通信、路由选择机制、安全策略控制等关键环节,并注意不同设备型号间的命令差异。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值