uva 11691 - Allergy Test(DP+map)
来源:互联网 发布:全球最贵的十大域名 编辑:程序博客网 时间:2024/06/07 00:31
Problem C - Allergy Test
Time limit: X seconds
A test for allergy is conducted over the course of several days, andconsists of exposing you to different substances (so calledallergens). The goal is to decide exactly which of the allergens youare allergic to. Each allergen has a live durationDmeasured in whole days, indicating exactly how many days you willsuffer from an allergic reactionif you are allergic to thatparticular substance. An allergic reaction starts to show almostimmediately after you have been exposed to an allergen which you areallergic to. The test scheme has two action points per day:
- At 8 o'clock each morning, at most one of the allergens is applied to your body.
- At 8 o'clock each evening, you are examined for allergic reactions.
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 beingtested for. Then followk lines each containing aninteger D (1 ≤ D ≤ 7) specifying the liveduration 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 activeallergens in your body, thus a test scheme for a single allergen withlive durationD takes D days.
Sample Input
23222514252
Sample Output
510这一题把题意转化一下,画图会清晰一点,有空再画!这一题一直苦恼数组开不了那么大!int dp[8][21][21][21][21][21][21][21],8表示当前状态可以节省的天数,其余21表示每一种D的个数,但是数组开不了这么大!所以,用map<long long , int> dp[8]就轻松解决啦~把后面的21转换成long long ,每个21占2位,总共14位,long long 完全可以!#include <iostream>#include <cstdio>#include <vector>#include <map>#include <algorithm>using namespace std;#define ll long longconst int maxn = 10;int D[maxn] , k;map<ll , int> dp[maxn];void initial(){for(int i = 0;i < maxn;i++){D[i] = 0;}}void readcase(){scanf("%d" ,&k);for(int i = 0;i < k;i++){int d;scanf("%d" , &d);D[d]++;}}int DP(int k){ll tem = 0;for(int i = 7;i >= 1;i--){tem = tem*100+D[i];}//cout << tem << "P"<<endl;if(tem == 0) return 0;if(dp[k].find(tem) != dp[k].end()) return dp[k][tem];int ans = 1e9;for(int i = 1;i <= 7;i++){if(D[i] > 0){D[i]--;ans = min(ans , DP(max(0 , i-k-1))+max(1 , i-k));D[i]++;}}return dp[k][tem] = ans;}void computing(){printf("%d\n" , DP(0));}int main(){freopen("in" , "r" , stdin);int N;cin >> N;while(N--){initial();readcase();computing();}return 0;}
- uva 11691 - Allergy Test(DP+map)
- UVA 11691 - Allergy Test(状压dp+贪心)
- UVA 11691 Allergy Test(状压dp)
- uva 11691 - Allergy Test(状态压缩+记忆化)
- UVA - 11691(dp 集合类)
- [转]Dyson DC08 Allergy
- google map test
- map/reduce unit test
- test——map
- UVa 416 - LED Test
- UVA - 10981(dp ,map做内存类,仍没算出最大内存)
- 集合—Map—Test
- UVA 11991 map应用
- uva 417 map暴力
- UVa--156 Ananagrams (map)
- UVA 156 - Ananagrams (map)
- uva 10553 Treasure Map
- UVA 1592 map用法
- php apc 安装
- 二维数组类Douary
- Solr4.4 docValues解析和性能测试
- Emacs AUCTeX 解决不能插入高版本pdf图片的问题
- Android APP增量升级的实现方式
- uva 11691 - Allergy Test(DP+map)
- 初探 jQuery 的 Sizzle 选择器
- static 作用
- Android ViewPager一分钟入门教程-ViewPager实例
- oracle表空间简介
- JavaScript验证表单函数大全
- ExtJS学习笔记之一-------ExtJs与jQuery的比较
- win764位系统安装Oracle11Gr2报错:Oracle Database Configuration Assistant失败。
- 自己的第一个博客