题目大意

  • 给一个数列,找出存在不能组合的最短位数

  • 例子:
    它到一位数,两位数的所有情况都能组成,三位数:没有 2 2 4 这种情况

    1 5 3 2 5 1 3 4 4 2 5 1 2 3

题目分析(思维题):

  • 根据例子:[1-k]组成所有一位数,[1-k][1-k]组成所有两位数,最多满足两位,那么答案就是3
  • 那么记录1到k所有数出现的次数,若全部出现,就满足一个位数
  • 最终输出满足最大位数+1

代码如下

#include<iostream>
#include<cstring>

using namespace std;

const int N = 1e4 + 10;
int n,k;
int cnt;
bool st[N];
int idx_st;

inline void quickread(){
     ios::sync_with_stdio(0);cin.tie(0);
}

int main(){
    quickread();
    cin >> n >> k;
    for(int i = 0; i < n; i ++ ){
        int x; cin >> x;
        if(!st[x]) st[x] = true,idx_st++;
        if(idx_st == k) cnt++,memset(st,0,sizeof st),idx_st = 0;
    }
    cout<<cnt+1;
    return 0;
}