-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathPAML.cpp
More file actions
65 lines (60 loc) · 1010 Bytes
/
PAML.cpp
File metadata and controls
65 lines (60 loc) · 1010 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#include <iostream>
#include <vector>
#include <cmath>
#include <cstring>
#include <algorithm>
using namespace std;
int main(){
int t;
cin>>t;
while(t--){
int n,maxv=0,count,gmax=0;
cin>>n;
vector<int> a(n),b;
for (int i = 0; i < n; i++)
{
cin>>a[i];
}
sort(a.begin(),a.end());
b=a;
count=0;
while(1){
count++;
maxv=0;
int size=b.size();
cout<<size<<" "<<endl;
vector<int> maxi(size,0),c(size,0);
for (int i = 0; i < size; i++)
{
int index;
maxv=0;
for (int j = 1; j <= b[i] && i - j >= 0 ; j++)
{
if(maxi[i-j]>maxv && b[i]>=maxi[i-j])
{
maxv=maxi[i-j];
index=i-j;
}
}
c[index]=1;
maxi[i]=maxv+1;
}
if(gmax>maxi[size-1])
gmax=maxi[size-1];
vector<int> temp;
bool check=true;
for (int i = 0; i < size; i++)
{
if(c[i]==0){
temp.push_back(b[i]);
check=false;
}
}
if(check)
break;
b=temp;
}
cout<<gmax<<" "<<count<<endl;
}
return 0;
}