Problem Statement
Your master construction unit can build 1 unit of type 0 in times[0] seconds at a cost of costs[0]. Each unit of type 0, once built, can in turn build 1 unit of type 1 in times[1] seconds at a cost of costs[1]. Type 1 units can build units of type 2, and so forth. Let N denote the number of elements in times. Given totTime seconds, return the greatest number of units of type N-1 that can be created without exceeding a total cost of totCost.
Definition
Class:
ProductionOptimization
Method:
getMost
Parameters:
int[], int[], int, int
Returns:
int
Method signature:
int getMost(int[] costs, int[] times, int totCost, int totTime)
(be sure your method is public)
Constraints
-
costs will contain between 2 and 50 elements, inclusive.
-
times will contain the same number of elements as costs.
-
Each element of costs will be between 1 and 100, inclusive.
-
Each element of times will be between 1 and 100, inclusive.
-
totTime will be between 1 and 100, inclusive.
-
totCost will be between 1 and 100, inclusive.
Examples
0)
{1,1}
{1,1}
3
3
Returns: 2
Build 1 unit 0, and then 2 of unit 1.
1)
{1,1}
{1,1}
5
3
Returns: 3
Build 2 of unit 0. The first will be able to build 2 of unit 1. The second will be able to build 1.
2)
{ 1,1,1,1,1,1,1,1,1,1, 1,1,1,1,1,1,1,1,1,1, 1,1,1,1,1,1,1,1,1,1, 1,1,1,1,1,1,1,1,1,1, 1,1,1,1,1,1,1,1,1,1}
{ 1,1,1,1,1,1,1,1,1,1, 1,1,1,1,1,1,1,1,1,1, 1,1,1,1,1,1,1,1,1,1, 1,1,1,1,1,1,1,1,1,1, 1,1,1,1,1,1,1,1,1,1}
100
100
Returns: 51
A lot of unit types.
3)
{1, 1}
{3, 12}
100
27
Returns: 6
4)
{20,1}
{20,1}
17
19
Returns: 0
import java.util.Arrays;
public class ProductionOptimization {
int[][][] dp = new int[64][128][128];
int[] costs, times;
int solve(int i, int c, int t) {
if (dp[i][c][t] != -1)
return dp[i][c][t];
if (i == costs.length)
return 1;
int c2 = c - costs[i];
int t2 = t - times[i];
if (c2 < 0 || t2 < 0)
return 0;
int ret = 0;
for (int k = 0; k <= c2; k++)
ret = Math.max(ret, solve(i, k, t2) + solve(i + 1, c2 - k, t2));
return dp[i][c][t] = ret;
}
public int getMost(int[] costs, int[] times, int C, int T) {
this.costs = costs;
this.times = times;
for (int[][] a : dp)
for (int[] b : a)
Arrays.fill(b, -1);
return solve(0, C, T);
}
}
发表评论
-
TCHS-12-950
2010-03-01 12:58 784Problem Statement ... -
TCHS-12-550
2010-03-01 10:04 707Problem Statement ... -
TCHS-12-250
2010-02-28 09:53 721Problem Statement ... -
TCHS-11-1000
2010-02-22 15:22 671Problem Statement ... -
TCHS-11-500
2010-02-22 13:11 799Problem Statement ... -
TCHS-11-250
2010-02-22 11:38 721Problem Statement ... -
TCHS-10-1000
2010-02-21 16:35 690Problem Statement ... -
TCHS-10-500
2010-02-21 15:16 765Problem Statement ... -
TCHS-10-250
2010-02-21 14:26 768Problem Statement ... -
TCHS-9-1000
2010-02-20 18:45 704Problem Statement ... -
TCHS-9-500
2010-02-20 16:26 1328Problem Statement ... -
TCHS-9-250
2010-02-20 15:24 690Problem Statement ... -
TCHS-8-1000
2010-02-19 11:57 687Problem Statement ... -
TCHS-8-500
2010-02-19 10:56 760Problem Statement ... -
TCHS-8-250
2010-02-19 10:18 615Problem Statement ... -
TCHS-7-1000
2010-02-05 15:21 692Problem Statement ... -
TCHS-7-500
2010-02-05 13:45 693Problem Statement ... -
TCHS-7-250
2010-02-05 13:32 781Problem Statement ... -
TCHS-6-900
2010-02-04 12:06 676Problem Statement ... -
TCHS-6-600
2010-02-04 11:33 709Problem Statement ...
相关推荐
TCHS-SRM-1 SRM - 算法单轮比赛 2. USACO - C++11 礼物1.cpp 骑车.cpp 测试.cpp 3.乌拉尔 - - C++11,Java 1.8 乌拉尔在线法官的可能解决方案 反向Root.cpp 总和文件 求和程序 最终排名.cpp 磁暴.cpp 磁暴.java 寂寞...
- 计算`PDCHS_zhuan`和`TCHS_zhuan`(专用数据信道和语音信道转换后的数量)。 - 计算`DSP_pdch`和`DSP_tch`(所需的数字信号处理器数量)。 #### 输出结果 - 使用`printf`函数输出计算结果,包括基站数量、链路接...
TCHs(时隙分配)、TRXSIG(发射信号)和OMUSIG(操作维护信道)是需要配置的。 5. **电源模块**:DE34基站的公共设备直流电源由CSUA模块提供。 6. **GSM多址方式**:GSM系统采用FDMA(频分多址)和TDMA(时分多址...
4. 配置ULTRASITE传输时,不需要配置EDAP(可能是指电子数据接入点),而需要配置TCHs(时隙信道)、TRXSIG(传输信号)和OMUSIG(操作维护信号)。 5. DE34基站的公共设备直流电源由CSUA模块提供,而非PWSB、PSUA...
电路交换业务信道(TCHs)测试是BER测试的重要组成部分,主要用于评估语音和低速数据服务的质量。这一部分将详细介绍如何设置测试环境并执行测试。 #### 分组数据业务信道(PDTCHs)测试 随着数据传输速度的提高,...
要告诉技术人员验证元素,请将“tchs”属性添加到元素。 <input type="text" tchs=""></input> 技术人员利用规则来验证元素。 验证是在每个元素的基础上完成的,并且根据所使用的元素进行不同的工作...
此外,TopCoder竞赛提供了丰富的奖金和机会,如TopCoder Open(TCO)、TopCoder Collegiate Challenge(TCCC)和TopCoder High School(TCHS)等,涵盖算法、设计、开发和组装等领域。TopCoder Studio则专注于网页...