Im unable to understand the solution logic of codeforces div2 664 problem c. http://mirror.codeforces.com/contest/1395/problem/C
| # | User | Rating |
|---|---|---|
| 1 | Benq | 3792 |
| 2 | VivaciousAubergine | 3647 |
| 3 | Kevin114514 | 3603 |
| 4 | jiangly | 3583 |
| 5 | turmax | 3559 |
| 6 | tourist | 3541 |
| 7 | strapple | 3515 |
| 8 | ksun48 | 3461 |
| 9 | dXqwq | 3436 |
| 10 | Otomachi_Una | 3413 |
| # | User | Contrib. |
|---|---|---|
| 1 | Qingyu | 157 |
| 2 | adamant | 153 |
| 3 | Um_nik | 147 |
| 4 | Proof_by_QED | 146 |
| 5 | Dominater069 | 145 |
| 6 | errorgorn | 141 |
| 7 | cry | 139 |
| 8 | YuukiS | 135 |
| 9 | TheScrasse | 134 |
| 10 | chromate00 | 133 |
Im unable to understand the solution logic of codeforces div2 664 problem c. http://mirror.codeforces.com/contest/1395/problem/C
I tried to solve longest increasing subsequence in top down but only pass few cases i don't know whether it is full right or wrong here is the code which i tried
this question is from leetcode
int lis(vector<int>&nums,int i,int n,int prev,vector<int>& ls){
if(i==n||n==0){
return 0;
}
if(ls[i]!=-1){
return 1 ;
}
lis(nums,i+1,n,prev,ls);
if(nums[i]>prev){
int num=1+lis(nums,i+1,n,nums[i],ls);
ls[num]=1;
return num;
}
return 0;
}
class Solution {
public:
int lengthOfLIS(vector<int>& nums) {
int n=nums.size();
int c;
vector<int> ls(n+1,-1);
lis(nums,0,n,INT_MIN,ls);
for(int i=n;i>=0;i--){
if(ls[i]!=-1){
c=i;
break;
}
else{
c=0;
}
}
if(nums.size()==0){
return 0;
}
else{
if(c==0){
return 0;
}
else{
return c;
}
}
}
};I wants to how to write top-down approach of this question and wants to know the solution of this question in c++ can anyone explain me ?
Here is the link https://mirror.codeforces.com/contest/1000/problem/C I saw the editorial but cannot understand please explain the solution of this question.
The question is
https://mirror.codeforces.com/contest/489/problem/C
#include<bits/stdc++.h>
#include<math.h>
using namespace std;
int main(){long long int j,no,i,sum1,sum,d=0,d2=0,rem=0,i1,large,large1=0;
cin>>j>>no;
if(j>6){
cout<<0<<" "<<0;
}
if(j<6){
if(no==0){
cout<<-1<<" "<<-1;
}
else{
for(i=(pow(10,j)-1);i>=pow(10,(j-1));i--){
sum1=0;
sum=0;
i1=i;
while(i1!=0){
rem=i1%10;
sum1=sum1+rem;
sum=(sum*10)+rem;
i1=i1/10;
}
if(sum1==no){
d2=i;
large=i;
if(large1<=large){
large1=large;
}
}
}
if(no>1){
cout<<d2<<" "<<large1;
}
if(no==1){
cout<<i+1<<" "<<i+1;
}
}
}
return 0;
}| Name |
|---|


