各种方法

C - Allergy Test

Crawling in process... Crawling failed Time Limit:3000MS     Memory Limit:0KB     64bit IO Format:%lld & %llu

Submit Status Practice UVA 11691

Description

C - Allergy Test

Problem C - Allergy Test

Time limit: X seconds

A test for allergy is conducted over the course of several days, and consists of exposing you to different substances (so called allergens). The goal is to decide exactly which of the allergens you are allergic to. Each allergen has a live duration D measured in whole days, indicating exactly how many days you will suffer from an allergic reaction if you are allergic to that particular substance. An allergic reaction starts to show almost immediately after you have been exposed to an allergen which you are allergic to. The test scheme has two action points per day:

  1. At 8 o‘clock each morning, at most one of the allergens is applied to your body.
  2. At 8 o‘clock each evening, you are examined for allergic reactions.

Thus an allergen with live duration D will affect exactly D allergic reaction examinations. Of course, if you have two or more active allergens in your body at the time of an observed reaction, you cannot tell from that information only, which of the substances you are allergic to. You want to find the shortest possible test scheme given the durations of the allergens you want to test. Furthermore, to allow simple large scale application the test scheme must be non-adaptive, i.e. the scheme should be fixed in advance. Thus you may not choose when to apply an allergen based on the outcome of previous allergic reaction examinations.

Input

The first line of the input file contains an integer N (N<30) which denotes the total number of test cases. The description of each test case is given below:
The first line of the input contains a single integer k (1 ≤ k ≤ 20) specifying the number of allergens being tested for. Then follow k lines each containing an integer D (1 ≤ D ≤ 7) specifying the live duration of each allergen.

Output

For each test case, print in a single line the number of days of the shortest conclusive non-adaptive test scheme. A scheme ends the morning when you no longer have active allergens in your body, thus a test scheme for a single allergen with live duration D takes D days.

Sample Input

2
3
2
2
2
5
1
4
2
5
2

Sample Output

5
10

 1 #include <cstdio>
 2 #include <cstring>
 3 #include <queue>
 4 #include <map>
 5 #include <string>
 6 #include <cmath>
 7 #include <iostream>
 8 #include <time.h>
 9 #include <algorithm>
10 using namespace std;
11 #define ll long long
12 #define INF 0x7fffffff
13 #define mod 1000000000
14 #define maxn (1<<20)
15 int n, m, k, s, t, ans;
16 int dp[maxn][9];
17 int a[22],in[22],vis[22];
18 void dfs(int *b, int t){
19     int f[22];
20     if (t >= ans)return;
21     int flag = 1;
22     for (int i = 0; i < n; i++){
23         if (in[i] == 0)flag = 0;
24         if (b[i]<a[i])flag = 0;
25     }
26     if (flag){
27         ans = min(ans, t); return;
28     }
29     for (int i = 0; i < n; i++){
30         if (vis[i] == 1)b[i]++;
31     }
32     dfs(b, t + 1);
33     for (int i = 0; i < n; i++){
34         if (vis[i] == 1)b[i]--;
35     }
36     int x = 0,p;
37     for (int i = 0; i < n; i++){
38         if ((vis[i] && b[i] < a[i])){
39             x++;
40             p = i;
41         }
42     }
43     if (x == 1&&in[p]==0){
44         in[p] = 1;
45         dfs(b, t);
46         in[p] = 0;
47     }
48     for (int i = 0; i < n;i++)
49     if (vis[i] == 1)b[i]++;
50     for (int i = 0; i < n; i++){
51         if (b[i]>=a[i]||vis[i])continue;
52         vis[i] = 1;
53         dfs(b, t + 1);
54         vis[i] = 0;
55     }
56     for (int i = 0; i < n; i++)
57     if (vis[i] == 1)b[i]--;
58 }
59 int main(){
60     int T; scanf("%d", &T);
61     while (T--){
62         int b[22];
63         scanf("%d", &n);
64         for (int i = 0; i < n; i++){
65             scanf("%d", &a[i]);
66         }
67         ans = 82;
68         for (int i = 0; i < n; i++){
69             memset(in, 0, sizeof in);
70             memset(vis, 0, sizeof vis);
71             memset(b, 0, sizeof b);
72             vis[i] = 1;
73             dfs(b, 0);
74         }
75         printf("%d\n", ans);
76     }
77     return 0;
78 }

TLE方法。。。dfs这个dfs也是写的要死。。

各种方法

时间: 2024-08-07 21:19:28

各种方法的相关文章

Unity 崩溃问题解决方法——之一

友情提示:工作随记,不喜勿喷 注意:文艺青年可以略过,暴力青年欢迎采纳 Library文件夹 Unity每次编译都会生成这个东西,不用担心丢失的问题.所以,干掉他! 选中 + Delete   或者  选中 + Shift  + Delete 网上看了很多方法,就觉得这个简单,粗暴,是我喜欢的类型. 优点:上面说了 缺点:如果工程过大,重新编译时间会比较长.(但是对于查Log日志来说,相对快点)

Java TM 已被阻止,因为它已过时需要更新的解决方法

公司的堡垒机需要通过浏览器登陆,且该堡垒机的网站需要Java的支持,最近通过浏览器登陆之后总是提示"java TM 已被阻止,因为它已过时需要更新的解决方法"导致登陆之后不能操作, 但是操作系统中确实已经安装了比较新的JDK,安装的JDK版本是jdk-7u67-windows-i586,因为太烦人,所以决定搞清楚报错的原因,一劳永逸,彻底解决这个问题 准备工作:安装JDK,安装版本jdk-7u67-windows-i586.exe,因为机器的Eclipse还依赖64位的JDK,所以另安

win7 64位系统 PB连接oracle数据库出现“oracle library oci.dll could not be loaded”问题的解决方法

今天与大家分享一个自己的学习笔记,希望能给遇到同样问题的人带来帮助. 不知道大家在win7 64位系统下用 PB连接oracle数据库时,是否遇到过“oracle library oci.dll could not be loaded”问题. 今天,在win7 64位系统下用 PB连接oracle数据库时,一直出现上述错误,在百度上找了很久,都没有找到一个完整的解决方案,咨询了很多人,(他们都说是我的PB和oracle没装好,但我装的时候没出现任何问题,一切都很顺利,而且PB和oracle都能正

C#与数据库访问技术总结(八)之ExecuteNonQuery方法

ExecuteNonQuery方法 ExecuteNonQuery方法主要用来更新数据. 通常使用它来执行Update.Insert和Delete语句. 该方法返回值意义如下: 对于Update.Insert和Delete语句,返回值为该命令所影响的行数. 对于所有其他类型的语句,返回值为-1. Command对象通过ExecuteNonQuery方法更新数据库的过程非常简单,需要进行的步骤如下: (1)创建数据库连接. (2)创建Command对象,并指定一个SQL Insert.Update

android开发之onCreate( )方法详解

onCreate( )方法是android应用程序中最常见的方法之一,那么,我们在使用onCreate()方法的时候应该注意哪些问题呢? 先看看Google Android Developers官网上的解释: onCreate(Bundle) is where you initialize your activity. Most importantly, here you will usually call setContentView(int) with a layout resource d

MAC平台下Xcode配置使用OpenCV的具体方法 (2016最新)

1.序言: 1.1 背景 本人小白一枚,不过因为最近在从事机器视觉方面的工作,所以接触到OpenCV. 因为工作需求,本人要在MAC端使用OpenCV实现一些视觉功能,配置环境成了最大的阻碍,网上查了很多相关资料和博客,都因为版本环境问题屡试屡败,不过经历重重尝试,笔者最终还是配置成功并运行了自己的源码.当然成功的关键还是因为笔者站在了巨人的肩膀上,借鉴了很多网上的教程,为了不误导大家配置的过程,参考文章的地址统一放在文章里,望各位大大看见之后能够理解,废话不说进入正题. 1.2 环境说明 如果

正则化方法:L1和L2 regularization、数据集扩增、dropout

本文是<Neural networks and deep learning>概览 中第三章的一部分,讲机器学习/深度学习算法中常用的正则化方法.(本文会不断补充) 正则化方法:防止过拟合,提高泛化能力 在训练数据不够多时,或者overtraining时,常常会导致overfitting(过拟合).其直观的表现如下图所示,随着训练过程,网络在training data上的error渐渐减小,但是在验证集上的error却反而渐渐增大--因为训练出来的网络过拟合了训练集,对训练集外的数据却不work

mac上 go-delve 安装出现The specified item could not be found in the keychain 解决方法

安装go语言的编译环境,在安装到 delve时候出现如下错误: If reporting this issue please do so at (not Homebrew/brew or Homebrew/core): https://github.com/go-delve/homebrew-delve/issues These open issues may also help: Upgrade to delve fails https://github.com/go-delve/homebr

初识运维3--在虚拟机中安装Linux发行版系统(CentOS)的方法

在讲Linux系统发行版本的安装过程之前,先大略说明一下虚拟化. 虚拟化:将底层硬件资源抽象为用户更容易读懂和使用的逻辑抽象层的技术. 最早由IBM提出,现使用率较高的虚拟化软件平台有三类:VMware workstation.VirtualBOX.HyperV.在这里使用VMware workstation作为例子讲解说明安装过程. 虚拟化网络: 桥接模式:让物理机和虚拟机利用物理网络接口完成通信.虚拟机可以访问互联网. 仅主机模式:让虚拟机和物理机利用被虚拟出来的VMnet1网络接口完成通信

《个人-GIT使用方法》

本文章转载于:http://blog.csdn.net/gemmem/article/details/7290125 1. Git概念 1.1. Git库中由三部分组成 Git 仓库就是那个.git 目录,其中存放的是我们所提交的文档索引内容,Git 可基于文档索引内容对其所管理的文档进行内容追踪,从而实现文档的版本控制..git目录位于工作目录内. 1) 工作目录:用户本地的目录: 2) Index(索引):将工作目录下所有文件(包含子目录)生成快照,存放到一个临时的存储区域,Git 称该区域