Car
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 272 Accepted Submission(s): 113
Problem Description
W 市最近面临了严重的交通拥堵问题,现在决定要在工作日(周一到周五)限号。
每天可以限制若干尾号的车辆,譬如说周一限尾号为 0 的车,周二限尾号为 1,2 的车。
每个尾号在五天当中最多只能被限一次,一天也可以什么牌照都不限。
我们要设置一个容量上限 m,使得至少存在一种方案,每一天不被限号的车的总数都小于等于 m。
请求出最小的 m。
每天可以限制若干尾号的车辆,譬如说周一限尾号为 0 的车,周二限尾号为 1,2 的车。
每个尾号在五天当中最多只能被限一次,一天也可以什么牌照都不限。
我们要设置一个容量上限 m,使得至少存在一种方案,每一天不被限号的车的总数都小于等于 m。
请求出最小的 m。
Input
第一行一个整数 test(1≤test≤10) 表示数据组数。
对于每组数据,第一行一个正整数 n(1≤n≤10000) 表示这个城市里有多少辆车。
接下来 n 行,每行一个字符串表示车牌。车牌由 5 位字符构成,每位都是'0'-'9'的数字。两辆车的车牌可能相同。
对于每组数据,第一行一个正整数 n(1≤n≤10000) 表示这个城市里有多少辆车。
接下来 n 行,每行一个字符串表示车牌。车牌由 5 位字符构成,每位都是'0'-'9'的数字。两辆车的车牌可能相同。
Output
对于每组数据,一行一个整数表示答案。
Sample Input
2
1
00000
10
00000
00001
00002
00003
00004
00005
00006
00007
00008
00009
Sample Output
1
8
Source
Recommend
heyang
析:我做的方式和官方题解不一样,我没有使用二分,直接dp[i][state] 表示前 i 天,已经限号的尾号的状态是 state,在第 i 天时,只需要每次枚举剩下的还没有限号的尾号,需要和前 i-1 取的最大值,然后再在第 i 天中取个最小值即可
#pragma comment(linker, "/STACK:1024000000,1024000000")
#include <cstdio>
#include <string>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <cstring>
#include <set>
#include <queue>
#include <algorithm>
#include <vector>
#include <map>
#include <cctype>
#include <cmath>
#include <stack>
#include <sstream>
#include <list>
#include <assert.h>
#include <bitset>
#include <numeric>
#include <unordered_map>
#define debug() puts("++++")
#define print(x) cout<<(x)<<endl
// #define gcd(a, b) __gcd(a, b)
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define fi first
#define se second
#define pb push_back
#define sqr(x) ((x)*(x))
#define ms(a,b) memset(a, b, sizeof a)
#define sz size()
#define be begin()
#define ed end()
#define pu push_up
#define pd push_down
#define cl clear()
#define lowbit(x) -x&x
#define all 1,n,1
#define FOR(i,n,x) for(int i = (x); i < (n); ++i)
#define freopenr freopen("in.in", "r", stdin)
#define freopenw freopen("out.out", "w", stdout)
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int, int> P;
const int INF = 0x3f3f3f3f;
const LL LNF = 1e17;
const double inf = 1e20;
const double PI = acos(-1.0);
const double eps = 1e-8;
const int maxn = 1024 + 7;
const int maxm = 2000000 + 7;
const LL mod = 1e9 + 7;
const int dr[] = {-1, 1, 0, 0, 1, 1, -1, -1};
const int dc[] = {0, 0, 1, -1, 1, -1, 1, -1};
int n, m;
inline bool is_in(int r, int c) {
return r >= 0 && r < n && c >= 0 && c < m;
}
inline int readInt(){
int x; cin >> x; return x;
}
const int limit = 1024;
unordered_map<int, int> mp;
int dp[7][maxn];
int get_num(int state){
int res = n;
for(int i = 0; i < 10; ++i)
if(state&1<<i) res -= mp[i];
return res;
}
int main(){
int T; scanf("%d", &T);
while(T--){
scanf("%d", &n); mp.cl;
for(int i = 0; i < n; ++i){
scanf("%d", &m);
++mp[m%10];
}
ms(dp, INF);
for(int i = 0; i < limit; ++i){
int res = n;
for(int j = 0; j < 10; ++j)
if(i&1<<j) res -= mp[j];
dp[1][i] = res;
}
for(int i = 2; i <= 5; ++i){
for(int j = 0; j < limit; ++j){
int s = j ^ limit - 1;
for(int s0 = s; s0; s0 = (s0-1) & s){
dp[i][j|s0] = min(dp[i][j|s0], max(get_num(s0), dp[i-1][j]));
}
}
}
int ans = INF;
for(int i = 0; i < limit; ++i)
ans = min(ans, dp[5][i]);
printf("%d
", ans);
}
return 0;
}