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 | #include <iostream> using namespace std; const int maxn=10000; int n; int a[maxn]; int b[maxn]; int f(int l,int r, int depth){ if(l>r) return 0; int min=maxn,mink; for (int i = 0; i <=r; i++){ if (min>a[i]){ min=a[i]; mink=i; } } int lres=f(l,mink-1,depth+1); int rres=f(mink+1,r,depth+1); return lres+rres+depth*b[mink]; } int main(){ cin>>n; for (int i = 0; i < n; i++) cin>>a[i]; for (int i = 0; i < n; i++) cin>>b[i]; cout<<f(0,n-1,1)<<endl; return 0; } |
0 of 6 Questions completed
Questions:
You have already completed the quiz before. Hence you can not start it again.
Quiz is loading…
You must sign in or sign up to start the quiz.
You must first complete the following:
0 of 6 Questions answered correctly
Your time:
Time has elapsed
You have reached 0 of 0 point(s), (0)
Earned Point(s): 0 of 0, (0)
0 Essay(s) Pending (Possible Point(s): 0)
1. 如果a数组有重复的数字,则程序运行时会发生错误( )
2.如果b数组全为0,则输出为0。( )
3.当n=100时,最坏情况下,与第12行的比较运算执行的次数最接近的是( )
4.当n=100时,最好情况下,与第12行的比较运算执行的次数最接近的是()。
5.当n=10时,若b数组满足,对任意0<=i<n,都有b[i]=i+1,那么输出最大为( )
6.当n=100时,若b数组满足,对任意0<=i<n,都有b[i]=1,那么输出最小为( )。