Basically, we need to count all the valid subsets.
Counting problems sometimes are hard.
subset [3, 2, 1] could be divided as [3] [2] [3, 2] [1] [2, 1] [3,2 ,1]
how can we count it?
adding a new number in all the previous subset, would generate the corresponding same number of subsets.
so the ans(i) += number of element(0 ~ i)
class Solution {
public:
long long getDescentPeriods(vector<int>& prices) {
long diff[1000000];
long n = prices.size();
memset(diff, 0, sizeof(diff));
for(int i = 1; i < n; i++)diff[i] = prices[i] - prices[i - 1];
long ans = n;
long cnt = 0;
for(int i = 1; i < n; i++){
if(diff[i] == -1){
cnt++;
ans += cnt;
}else{
cnt = 0;
}
}
return ans;
}
};