( dài nhất bay lên tử danh sách đơn giản dp )

Tuy rằng là đơn giản dp nhưng ta chính là làm không được T^T
J - X and Beasts
X is fighting beasts in the forest, in order to have a better chance to survive he’s gonna buy upgrades for his weapon. Weapon upgrade shops are available along the forest, there are n shops, where the ith of them provides an upgrade with energy ai. Unfortunately X can make use only of the maximum power of two that divides the upgrade energy, lets call it the powerincrement. For example, an upgrade with energy of 6 has a power increment of 1 because 6 is divisible by 21 but not divisible by 22 or more, while for upgrade with energy of 5 power increment is 0, also after buying a weapon with energy v, X can only buy upgrades with energies greater than v, in other words, the upgrades energies that X is gonna buy should be in strictly increasing order. X is wondering what is the maximum power he can achieve at the end of his journey. note that only the energy of upgrades should be in strictly increasing order not the power increment of the upgrade. 1 < n < 100, 1 ≤ ai ≤ 106

Input
The first line of input contains one integer, T, which denotes number of test cases. Each test case contains two lines, the first one contains one integer n which denotes number of shops, and the next line contains n integers the ith of them denotes the energy of the upgrade provided by the ith shop.

Output
Print one integer denotes maximum power X can achieve at the end of his journey

Example
Input
2
3
1 10 16
2
8 12
Output
5
5
Đề ý: Ấn đưa vào bay lên tử danh sách có thể bị 2 vài lần mịch chia hết lớn nhất cùng

#include <stdio.h>
#include <algorithm>
#include <memory.h>
#include <string.h>
#define ll long long
#define INF 0x3f3f3f3f
using namespace std;
int fin(int x)
{
int count=0;
while(x%2!=1)
{
count++;
x/=2;
}
return count;
}
int main()
{
int T,i,j,n,ans,a[101],dp[101];
scanf( "%d",&T);
while(T--)
{
memset(dp,-1,sizeof(dp));
scanf( "%d",&n);
for(i=0; i<n; i++)
{
scanf( "%d",&a[i]);
}
for(i=0; i<n; i++)
{
dp[i]=fin(a[i]);
for(j=0; j<i; j++)
{
if(a[i]>a[j])
{
dp[i]=max(dp[j]+fin(a[i]),dp[i]);
}
}
}
ans=-1;
for(i=0; i<n; i++)
{
//printf( "%d",dp[i]);
ans=max(ans,dp[i]);
}
printf( "%d\n",ans);
}
return 0;
}
// dài nhất bay lên tử danh sách a a a a ta chính là cái thái kê (cùi bắp) a T^T

D - Sequences
One of the most wonderful qualities of an ACMer is to be multi interests so he combines multiple qualifications and hobbies not just coding. Hussain is one of the most qualified ACMers to mention when talking about hobbies and other domains of personality training despite of his qualifications in ACM problem solving and math. It’s very known about Hussain his obsession in hunting and shooting, he used to pass hours training on empty cans in his childhood. These days, Hussain became a professional and still challenge others in this game, but for his bad luck he accidentally challenged a professional ACMer, without mentioning the name, so this ACMer made a game for Hussain. He numbered N targets for Hussain with random numbers and challenged him to shoot the minimum number of targets so the remaining numbers will form a sequence of increasing (by one) numbers in their current order. Example: if there is 6 targets numbered as follow: 2 5 7 3 2 4 Hussain will shoot 5,7 and the second 2 remaining for 2 3 4. Now, Hussain will focus on shooting, we will help him and focus on the targets he must shoot. But No! Hussain is an very good ACMer, we will make it hard for him and just tell him the number of the remaining targets in the sequence.

Input
First line contain an integer T represents the number of test cases 0 < T < 100, each test case consists of two lines, the first one is an integer 0< N < 20000 represents the number of targets, then followed by the second line that contains N numbers each number 0 < Xi < 20000 represents the number written on the i’th target.

Output
For each test case print one number represents the remaining sequence’s length can be created by the input where it should be the maximum length and each number of it follow its previous by 1.

Examples
Input
4
6
2 5 7 3 2 4
7
2 18 65 33 11 5 4
5
2 7 5 9 3
5
9 8 7 10 11
Output
3
1
2
3
Note
Please consider a large input file.
Tìm dài nhất bay lên tử danh sách, yêu cầu là cần thiết là liên tục con số tỷ như 3-4-5

#include <stdio.h>
#include <algorithm>
#include <memory.h>
#define ll long long
#define INF 0x3f3f3f3f
using namespace std;
int main()
{
int T,i,x,ans,n,dp[20010];
scanf( "%d",&T);
while(T--)
{
memset(dp,0,sizeof(dp));
scanf( "%d",&n);
ans = -INF;
for(i=0; i<n; i++)
{
scanf( "%d",&x);
dp[x]=1; // sắp xuất hiện hiện đánh dấu vì 1
dp[x]=dp[x-1]+1;// chính là tìm dài nhất bay lên tử danh sách nhưng hai cái tuần hoàn sẽ siêu khi
ans=max(ans,dp[x]);
}
printf( "%d\n",ans);
}
return 0;
}
ans = -INF; // sẽ siêu khi
for(i=0;i<n;i++)
{
dp[i]=1;
for(j=0;j<=i;j++)
{
if(a[i]==a[j]+1)
{
dp[i]=max(dp[j]+1,dp[i]);
}
}
ans = max(dp[i], ans);
}
  • 0
    Điểm tán
  • Dẫm
  • 0
    Cất chứa
    Cảm thấy cũng không tệ lắm? Một kiện cất chứa
  • 0
    Bình luận

“Tương quan đề cử” đối với ngươi có trợ giúp sao?

  • Phi thường không trợ giúp
  • Không trợ giúp
  • Giống nhau
  • Có trợ giúp
  • Phi thường có trợ giúp
Đệ trình
Bình luận
Tăng thêm bao lì xì

Thỉnh điền bao lì xì chúc phúc ngữ hoặc tiêu đề

Cái

Bao lì xì cái số nhỏ nhất vì 10 cái

Nguyên

Bao lì xì kim ngạch thấp nhất 5 nguyên

Trước mặt ngạch trống3.43Nguyên Đi trước nạp phí >
Cần chi trả:10.00Nguyên
Thành tựu một trăm triệu kỹ thuật người!
Lĩnh sau ngươi sẽ tự động trở thành bác chủ cùng bao lì xì chủ fans Quy tắc
hope_wisdom
Phát ra bao lì xì
Thật phóNguyên
Sử dụng ngạch trống chi trả
Điểm đánh một lần nữa thu hoạch
Quét mã chi trả
Tiền bao ngạch trống 0

Để khấu thuyết minh:

1. Ngạch trống là tiền bao nạp phí giả thuyết tiền, dựa theo 1:1 tỉ lệ tiến hành chi trả kim ngạch để khấu.
2. Ngạch trống vô pháp trực tiếp mua sắm download, có thể mua sắm VIP, trả phí chuyên mục cập chương trình học.

Ngạch trống nạp phí