L Clock Master(分组背包)2020 China Collegiate Programming Contest Weihai Site

With the rapid development of society, the demand for high-precision clocks is constantly rising. Recently, the China Clock Production Company is developing a new type of clock, which can represent a wide range of times.

The novel clock displays the current time in an unusual fashion. The clock consists of several pointers, each controlled by a gear. All gears rotate synchronously – one tooth per period. However, the numbers of teeth of the gears may differ. If a gear has t teeth, then the corresponding pointer can point to t different directions, denoted 0,1,2,⋯,t−1, respectively, where 0 is the initial direction. Furthermore, if a clock is equipped with n pointers, the i-th of which is controlled by a t​i​​ -tooth gear, then the i-th pointer will point to k mod t​i​​ after k periods of time.

The price for a t-tooth gear is t yuan. Given a total budget of b yuan, you need to design a combination of gears, such that the number of valid combinations of directions of pointers is maximized, and the total cost on gears does not exceed the budget. A combination of directions (d​1​​ ,d​2​​ ,⋯,d​n​​ ) is valid, if it can be written for some nonnegative integer k, where t​i​​ is the number of teeth of the i-th gear. Since the answer may be too large, output the answer in natural logarithm (logarithm with base e=2.718281828⋯).
1<T<30000
1<b<30000

Sample Input:

3
2
7
10

Sample Output:

0.693147181
2.484906650
3.401197382

题目大意

T组数据,
给你一个n,让你找若干个数xi,使得x1+x2+…xi<=n,且lcm(x1,x2,…,xi)最大
输出log(lcm)

思路

对于一个数n,要使他的lcm最大,那么就要保证xi两两互质(这样才能没有浪费)
因此xi可以看成某个质数的p次方,且该质数只能选择一次,例如3和9不能同时选,因为这样无法保证互质
那么很显然,问题被抽象成了分组背包,每个质数为一组,组里为该质数的p次方,背包容量为n,每件物品的贡献为log(xi)

CODE

#include<string>
#include<set>
#include<map>
#include<queue>
#include<stack>
#include<cmath>
#include<vector>
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
using namespace std;
#define LL long long
#define MOD 1000000007
#define MAXN 30050
LL read()
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值