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
 

 

Input
第一行一个整数 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
 

 

Statistic | Submit | Discuss | Note

析:我做的方式和官方题解不一样,我没有使用二分,直接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\n", ans);

  }
  return 0;
}

  

相关文章:

  • 2021-06-13
  • 2021-09-02
  • 2021-06-06
  • 2021-09-12
  • 2021-06-26
  • 2021-06-20
  • 2022-01-23
  • 2021-07-23
猜你喜欢
  • 2021-08-10
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-12-24
相关资源
相似解决方案