//贪心:重复求出当前最长的递减子序列,再将该子序列的元素拿出,继续重复求当前最长递减子序列,重复次数即为导弹拦截系统最少套数
//版本1:
#include<iostream>
#include<vector>
using namespace std;
struct D
{
int h;
bool used;
};
int main(void)
{
int n, count, nn,cur;
while (cin>>n)
{
vector<D>a(n);
for (int i = 0; i < n; i++)
{
cin >> a[i].h;
a[i].used = false;
}
nn = n;
count = 0;
while (nn)
{
for (int i = 0; i < n; i++)
{
if (!a[i].used)
{
cur = i;
a[i].used = true;
nn--;
break;
}
}
for (int i = cur + 1; i < n; i++)
{
if (a[i].h <= a[cur].h&&!a[i].used)
{
cur = i;
a[i].used = true;
nn--;
}
}
count++;
}
cout << count << endl;
}
return 0;
}
//改进版
#include<iostream>
using namespace std;
int a[10010];
int main(void)
{
int n, nn,count,cur;
while (cin >> n)
{
for (int i = 0; i < n; i++)
{
cin >> a[i];
}
nn = n;
count = 0;
while (nn)
{
for (int i = 0; i < n; i++)
{
if (a[i])
{
count++;
cur = a[i];
a[i] = 0;
nn--;
for (int j = i + 1; j < n; j++)
{
if ((a[j] <= cur) && a[j])
{
cur = a[j];
a[j] = 0;
nn--;
}
}
}
}
}
cout << count << endl;
}
return 0;
}
//动态规划:实质是求最长严格上升子序列的长度
#include<iostream>
#include<algorithm>
using namespace std;
int a[1010], dp[1010];
int main(void)
{
int n;
int ans;
while (cin >> n)
{
ans= 1;
for (int i = 0; i < n; i++)
{
cin >> a[i];
dp[i] = 1;
for (int j = 0; j < i; j++)
{
if (a[j] < a[i]) dp[i] = max(dp[i], dp[j] + 1);
}
ans = max(ans, dp[i]);
}
cout << ans << endl;
}
return 0;
}
//版本1:
#include<iostream>
#include<vector>
using namespace std;
struct D
{
int h;
bool used;
};
int main(void)
{
int n, count, nn,cur;
while (cin>>n)
{
vector<D>a(n);
for (int i = 0; i < n; i++)
{
cin >> a[i].h;
a[i].used = false;
}
nn = n;
count = 0;
while (nn)
{
for (int i = 0; i < n; i++)
{
if (!a[i].used)
{
cur = i;
a[i].used = true;
nn--;
break;
}
}
for (int i = cur + 1; i < n; i++)
{
if (a[i].h <= a[cur].h&&!a[i].used)
{
cur = i;
a[i].used = true;
nn--;
}
}
count++;
}
cout << count << endl;
}
return 0;
}
//改进版
#include<iostream>
using namespace std;
int a[10010];
int main(void)
{
int n, nn,count,cur;
while (cin >> n)
{
for (int i = 0; i < n; i++)
{
cin >> a[i];
}
nn = n;
count = 0;
while (nn)
{
for (int i = 0; i < n; i++)
{
if (a[i])
{
count++;
cur = a[i];
a[i] = 0;
nn--;
for (int j = i + 1; j < n; j++)
{
if ((a[j] <= cur) && a[j])
{
cur = a[j];
a[j] = 0;
nn--;
}
}
}
}
}
cout << count << endl;
}
return 0;
}
//动态规划:实质是求最长严格上升子序列的长度
#include<iostream>
#include<algorithm>
using namespace std;
int a[1010], dp[1010];
int main(void)
{
int n;
int ans;
while (cin >> n)
{
ans= 1;
for (int i = 0; i < n; i++)
{
cin >> a[i];
dp[i] = 1;
for (int j = 0; j < i; j++)
{
if (a[j] < a[i]) dp[i] = max(dp[i], dp[j] + 1);
}
ans = max(ans, dp[i]);
}
cout << ans << endl;
}
return 0;
}