6.30题目小结

1.先上一道题再说QAQ
hdu3466
Recently, iSea went to an ancient country. For such a long time, it was the most wealthy and powerful kingdom in the world. As a result, the people in this country are still very proud even if their nation hasn’t been so wealthy any more.
The merchants were the most typical, each of them only sold exactly one item, the price was Pi, but they would refuse to make a trade with you if your money were less than Qi, and iSea evaluated every item a value Vi.
If he had M units of money, what’s the maximum value iSea could get?
Input:
There are several test cases in the input.

Each test case begin with two integers N, M (1 ≤ N ≤ 500, 1 ≤ M ≤ 5000), indicating the items’ number and the initial money.
Then N lines follow, each line contains three numbers Pi, Qi and Vi (1 ≤ Pi ≤ Qi ≤ 100, 1 ≤ Vi ≤ 1000), their meaning is in the description.

The input terminates by end of file marker.
Output
For each test case, output one integer, indicating maximum value iSea could get.

题意简化版:
每个物品有 vali,wiqi ,在你身上的钱 >=qi 时才可以购买,可以调整顺序,求最大的价值。

f[i][j]=f[i1][jwi]+vali


这个东西还是想一想再看题解比较好.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
考虑这个题的解法,我一开始以为不排序就可以直接做背包,但是显然是不行的。
肯定要按某个顺序来。
考虑我们选i和j,那么考虑这样的选择:
先选i:则需要: qj+wi
先选j:则需要: qi+wj
i比j先选当且仅当: qj+wi<qi+wj
然后移项: qiwi>qjwj
考虑按照这个来排序然后向里面放物品就好了。
也就是说,我们考虑选择的时候是按照这个顺序进行选择的。
然而考虑01背包的转移:

for(int i = 1;i <= n;i ++)
    for(int j = m;j >= q[i];j --)
        f[j] = max(f[j - w[i]] + c[i],f[j]);

fi 代表的是容量为i的背包能够放多少价值的东西
考虑我们往里面放东西的时候实际上背包体积是单调下降的,
按照之前的排序方法,
而01背包的这种转移导致我们最后一个转移的时候是用最小的 qiwi 去更新 f[0...m]
然而实际上发现其实01背包是一个倒着买东西的过程,这样的话我们需要按照升序排序。
然后就没有了。


2.1433: [ZJOI2009]假期的宿舍
思路:
首先是个二分图一样的东西,因为一个床只能睡一个人,考虑到床与人的关系,可以发现如下的建图方式:
1.对于一个回家的人,那么对 S>i 连一个流量为1的边。
2.对于所有需要住的人对 i>T 连接流量

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值