zoj 3331 Process the Tasks(双塔DP)

广义平均(Generalized Mean, GeM) 本位介绍了广义平均操作的定义和简要推导,帮助大家理解其含义。 阅读详情

There are two machines A and B. There are n tasks, namely task 1, task 2, ..., task n. You must assign each task to one machine to process it. There are some facts you must know and comply with:

  • You must assign each task to only one machine to process.
  • At any time, a machine can process at most one task.
  • Task i (0 < i < n) can be processed if and only if each task j (0 < j < i) has been processed or processing.
  • If a task is processing on one machine, it cannot be interrupted.

You want to do finish all the tasks as soon as possible.

Input

There are multiple test cases. The first line of the input is an integer T (0 < T < 1000) indicating the number of test cases. ThenT test cases follow. Each test case starts with an integer n (0 < n < 100). The ith line of the next n lines contains two integerstA, tB (0 < tA, tB < 100), giving the time to process the ith task by machine A and machine B.

Output

For each test case, output the earliest time when all the tasks have been processed.

Sample Input

4
1
1 2
2
1 2
2 1
2
1 2
90 95
3
1 3
1 3
1 3

Sample Output

1
1
90
3

Hints

  • Test case 1: Let machine A process task 1.
  • Test case 2: Let machine A process task 1 and at the same time let machine B process task 2.
  • Test case 3: Let machine B process task 1 and at the same time let machine A process task 2.
  • Test case 4: Let machine A process all the tasks.

代码里是从 dp[i-1][j] 开始做状态转移的
就比如前面 j<= 100 的那个部分吧,
如果把任务给 A 做,两个机器的时间差就会变成 j + ta[i]
如果把任务给 B 做,因为 j <= 100 表示 B 正在处理一个任务,所以必须先等待那个任务做完(j 回到 100),然后再给 B(再从 100 变到 100 - tb[i])

j里面+100的原因是为了不让下标取到负

#include<iostream>
#include<algorithm>
#include<string>
#include<map>
#include<vector>
#include<cmath>
#include<string.h>
#include<stdlib.h>
#include<cstdio>
#define ll long long
using namespace std;
int dp[201][201],ta[101],tb[101],ans;
void init(void)  //双塔DP(本题取值1-100) 
{  
    int i,j;  
    for(i=0;i<201;i++){
        for(j=0;j<201;j++){
			dp[i][j]=100000000;  
		}
	}
    dp[0][100]=0;  //初始状态 
    ans=100000000;  
}
int main(void)  
{  
    int T,n,i,d,j;  
    scanf("%d",&T);  
    while(T--)  
    {  
        init();  
        scanf("%d",&n);  
        for(i=1;i<=n;i++)  
            scanf("%d%d",&ta[i],&tb[i]);  
        for(i=1;i<=n;i++)  
            for(j=0;j<=200;j++)  
            if(dp[i-1][j]!=100000000)  
            {  
                if(j<=100)  //b比a高
                {  
                    dp[i][100-tb[i]]=min(dp[i][100-tb[i]],dp[i-1][j]+tb[i]);  
                    dp[i][j+ta[i]]=min(dp[i][j+ta[i]],dp[i-1][j]+max(0,j-100+ta[i]));  
                }  
                else  //a比b高
                {  
                    dp[i][100+ta[i]]=min(dp[i][100+ta[i]],dp[i-1][j]+ta[i]);  
                    dp[i][j-tb[i]]=min(dp[i][j-tb[i]],dp[i-1][j]+max(0,tb[i]-(j-100)));  
                }  
            }  
            for(i=0;i<200;i++)
                ans=min(ans,dp[n][i]); //找出值最小的一个状态 
            printf("%d\n",ans);  
    }  
    return 0;  
}  


嵌入式面经篇八——进程&线程 记录一些招聘公司在招聘嵌入式软件岗位时的一些问题,此文为第八篇。进程上文:是指进程由用户态切换到内核态时需要保存用户态时CPU寄存器中的值,进程状态以及堆栈上的内容。即保存当前进程的状态,以便再次执行该进程时,能够恢复切换时的状态,继续执行。进程下文:是指切换到内核态后执行的程序,即进程运行在内核空间的部分。中断上文:硬件通过中断触发信号,导致内核调用中断处理程序,进入内核空间。这个过程中,硬件的一些变量和参数也要传递给内核,内核通过这些参数进行中断处理。 阅读详情

相关推荐

PyBioMed学习

PyProtein。

weixin_63016274的博客 1401

ZOJ-3331-Process the Tasks【7th浙江省赛】【双塔dp】【好题】

ZOJ-3331-Process the Tasks

Linoy 1693

Java 处理地理信息数据[DEM TIF文件数据获取高程]

EPSG 是一个国际标准,用于唯一标识地理坐标系和投影坐标系。

两点 1276

ZOJ 3331 Process the Tasks

Description There are two machines A and B. There are n tasks, namely task 1, task 2, ..., task n. You must assign each task to one machine to process it. There are some facts you must know and com

Occult 559

【大语言模型 14】Transformer权重初始化策略:从Xavier到GPT的参数初始化演进之路

权重初始化是深度学习训练成功的隐秘基石,特别是在Transformer这样的深层架构中,合适的初始化策略能够决定模型的训练稳定性和收敛速度。本文从经典的Xavier和He初始化出发,深入解析Transformer特有的初始化策略,通过数学推导、代码实现和实验分析,揭示不同初始化方法对大语言模型训练的深层影响。我们将探讨为什么GPT系列模型采用特定的初始化方案,以及如何针对不同层设计最优的初始化策略。

熵数实验室 1686

Python爬虫实战:高效爬取法律法规数据库的完整指南

本文将详细介绍如何使用Python最新技术栈构建一个高效、稳定的法律法规数据库爬虫。我们将从爬虫的基本原理讲起,逐步深入到反爬机制应对、数据解析与存储、性能优化等高级话题。文章包含完整的代码实现,使用requests-html、aiohttp等现代库,以及应对法律数据库特殊结构的处理技巧。通过本文,您将掌握构建专业级法律数据采集系统的全套技能。关键词:Python爬虫、法律法规、数据采集、异步爬虫、反反爬本文详细介绍了使用Python爬取法律法规数据库的完整技术方案。

2201_76125261的博客 1274

ZOJ3331-Process the Tasks(双塔DP)

Process the Tasks Time Limit: 1 Second      Memory Limit: 32768 KB There are two machines A and B. There are n tasks, namely task 1, task 2, ..., task n. You must assign each task to one machi

wang_128的博客 442

手把手教你学simulink(31.31)--双向DCDC电源场景示例:设计并实现一个基于变频控制的双向降压变换

设计并实现一个基于 Simulink 的双向降压变换器,能够在充电模式(从高压侧向低压侧传输能量)和放电模式(从低压侧向高压侧传输能量)之间切换,确保输出电压稳定,并根据负载变化自动调整工作模式。

MHD0815的博客 343

Process the Tasks(ZOJ3331)

题目链接:http://icpc.moe/onlinejudge/showProblem.do?problemCode=3331 题意:给两个机器,然后很多个操作,分别给出对应操作在AB两个机器上运作的时间,限定该操作能执行的条件是,前一个操作已完成或正在执行. http://blog.youkuaiyun.com/loy_184548/article/details/50733395 第一次接

Linnnnnger的博客 560

西门子V90伺服——章节0、西门子V90章节总述

格式规范:西门子V90伺服——章节1、产品介绍(1、伺服系统初步介绍)@[TOC](西门子V90伺服——章节1、产品介绍)课时1伺服系统初步介绍(1)课时2 伺服系统初步介绍(2)课时3 运动控制基础(1)课时4 运动控制基础(2)课时5 产品概览课时6 相关选件课时7 控制模式介绍(1)课时8 控制模式介绍(2)课时9 产品选型课时10 调试工具及相关资料介绍。

大小曲奇的博客 123

SKUA-GOCAD入门教程-第二节

软件启动及项目设置

江洋大葱的博客 1146

[DP]zoj 3331:Process the Tasks

大致题意:    有两个机器a,b。要处理n个部件,第i个部件在机器a上完成需要atime[i],在b机器上需要btime[i],每个部件只能选择一个机器来完成。且当地i个部件开始加工时前[1,i-1]部件必须已经完成或者正在被加工。求加工完所有n个部件的最小时间是多少。   大致思路:    好神的dp,开始时乱想了几个状态都觉得不靠谱,膜拜了众犇的博客才明白怎么做,大神敬请bs。这里的状态...

手上有剑,心中有爱 145

大津法(OTSU)点云强度信息分割

大津法(OTSU)是一种灰度图像自适应的阈值分割方法,大津法根据图像的灰度分布,将图像分成背景和前景两部分,前景就是需要按照阈值分割出来的部分。由于点云的强度信息的特性,也可以利用此方法进行分类,但需要保证信息干扰较少,例如道路标线分割等场景较为适用。

qq_48694523的博客 965

ZOJ 3331 Process the Tasks(双塔DP)

ZOJ 3331 Process the Tasks(双塔DP)

Dacc123的博客 688

VB摄像头监控

该VB模块可对摄像头捕获的画面进行录像等,可在创建的窗口进行控制

win10 跳过U8环境检测的IE WebControls.rar

win10 安装u8的时候 提示IE WebControls 不通过,这个工具可以欺骗u8的检查。 跳过U8环境检测的IE WebControls。提示导入失败后,重新检测通过。

ZOJ3331---Process the Tasks(dp)

There are two machines A and B. There are n tasks, namely task 1, task 2, ..., task n. You must assign each task to one machine to process it. There are some facts you must know and comply with:You mus

Alex 1186

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

TZOJ:3789: Process the Tasks(双塔DP)

这是一道经典的双塔DP题,建议没学过双塔的人先去学了再来弄这题吧. 最初始的双塔题好像是ZOJ上的那道------搭建双塔 但我学了把那道题弄懂后,再来写这道题的时候,还是没有任何思路,可能是我蠢爆了........ 无奈之下我翻了好几个博客去找题解,但几乎所有博客上讲的都有点粗枝大叶的,不够详细,我还得自己走几下代码,才能弄懂大致的思路,其中我看的一个博客,将大致的思路讲清楚了. ZOJ 3331 Process the Tasks(双塔DP)_Dacc123的博客-优快云博客 可以去翻一翻

Jay_fc的博客 207

Outlook Express 6 (OE6) for Win7/Win8/Win10

英文版 Outlook Express6.0, 兼容Win7/Win10/WinXP,解压就可用。

双塔DP---- 一类以差值为状态表示的DP

从AOJ的塔,到POJ的ferry loading,ferry loading到浙江省赛的第7题Process the Tasks,发现这三个问题都是一类比较典型的dp,有必要好好总结一下,避免以后再出现就不会了 这类题目比较原始的版本是 AOJ的塔问题(题目链接) 题意:给你一堆积木,选择其中的某些来组成两个相同高度的塔(对于某块积木,可以放在塔1,可以放在塔2,也可以都不放),问你最大组

yobobobo的专栏 1955

ZOJ 3331

题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3331题解:双塔dp。代码:#include <cmath> #include <cstdio> #include <cstring> #include <iostream> #include <algorithm> using namespace std; #def

silver_bone的博客 377

a人左扶手,b人右扶手,c人双扶手,z人不用扶手,求最多几人一起观看电影。

月赛第一次做上了5题!!放上来纪念一下,一道超级细心的分类讨论题,只有你想不到的情况。。。 #include #define mod 1000000007 #define ll unsigned long long using namespace std; int main(){ int t; scanf("%d",&t); while(t--){ ll n,m,z,a,b,c;

芒果街上的小屋(此博客暂时停用) 5万+

是否可以删除一个字母之后变成回文串

题目描述 给出一个字符串,仅由小写字母组成。请找出是否仅删除其中的一个字母之后, 字符串变成回文串。 输入 输入第一行是一个整数 T,表示有 T 组数据。 每组数据占一行,每行包含一个非空字符串,字符串长度不超过 105 。   输出 对于每组测试数据,输出一行包含一个整数 K ,表示删除字符串中第 K 个字 

芒果街上的小屋(此博客暂时停用) 1786

【codechef】交换字符串S的两个位置上的字符,求有多少对AB不相似

有一种操作,是交换字符串的两个位置上的字符(位置可以一样)。对于两个字符串A、B,如果分别对它们做这个操作后得出一样字符串C,那么称AB相似。 现在给出一个字符串S,A和B分别都是它的全排列里的一种。现在求有多少对A、B满足AB不相似。 //相似:A变化成C,B也变化成C,那么AB相似。那么不妨设B不动,A变化两次是否能到B。 //假设B是随便取的,A是顺着B取的,那么B在取每一种排列时都有

芒果街上的小屋(此博客暂时停用) 1614

hdu 5206:Four Inages Strategy(判断四个点能否组成正方形)

小F在祖屋中意外发现一本上古时代传承下来的秘籍,名为《四象阵法》,他按捺不住内心的激动,翻开秘籍,一字一句地读了起来,“用四块元石作为阵基摆放在空间四处位置,如果四块元石形成一个正方形,则阵法激活,有杀敌困敌之效”,小F走遍五湖四海,终于集齐了四块元石,并将四块元石放置在四个坐标点上,可是他不知道阵法是否能够成功激活,于是,由你来告诉他答案。 输入描述 第一行只有一个整数T(T≤10000

芒果街上的小屋(此博客暂时停用) 1257

POJ2411: Mondriaan's Dream(1*2铺地砖,DP)

Squares and rectangles fascinated the famous Dutch painter Piet Mondriaan. One night, after producing the drawings in his 'toilet series' (where he had to use his toilet paper to draw on, for all of h

芒果街上的小屋(此博客暂时停用) 1184

zoj 3177 Elune's Arrow(数学题,分类讨论)

Priestess of the Moon (PotM) is a very interesting hero in the game Defense of the Ancients (DotA). Here is the official description of PotM: "A matriarch and high priestess of Elune's blessed orde

芒果街上的小屋(此博客暂时停用) 1002

CF116D 一开始往右扫,每换下一行要换方向扫,问扫完草至少经过的步数

草是'W'。难点是很容易漏情况。 input 4 5 GWGGW GGWGG GWGGG WGGGG output 11 #include #include #include #include//int dx[4]={0,0,-1,1};int dy[4]={-1,1,0,0}; #include//int gcd(int a,int b){retu

芒果街上的小屋(此博客暂时停用) 960
上一篇: zoj 3177 Elune's Arrow(数学题,分类讨论)
下一篇: zoj 1734 Power Network(最大流模板)
ccyy-
博客等级 码龄12年 31粉丝 244原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值