源代碼\用動態規劃算法計算序列關系個數
用關系"<"和"="將3個數a,b,c依次序排列時,有13種不同的序列關系:
a=b=c,a=b<c,a<b=v,a<b<c,a<c<b
a=c<b,b<a=c,b<a<c,b<c<a,b=c<a
c<a=b,c<a<b,c<b<a
若要將n個數依序列,設計一個動態規劃算法,計算出有多少種不同的序列關系,
要求算法只占用O(n),只耗時O(n*n).
標簽:
lt
源代碼
動態規劃
序列
上傳時間:
2013-12-26
上傳用戶:siguazgb
We have a group of N items (represented by integers from 1 to N), and we know that there is some total order defined for these items. You may assume that no two elements will be equal (for all a, b: a<b or b<a). However, it is expensive to compare two items. Your task is to make a number of comparisons, and then output the sorted order. The cost of determining if a < b is given by the bth integer of element a of costs (space delimited), which is the same as the ath integer of element b. Naturally, you will be judged on the total cost of the comparisons you make before outputting the sorted order. If your order is incorrect, you will receive a 0. Otherwise, your score will be opt/cost, where opt is the best cost anyone has achieved and cost is the total cost of the comparisons you make (so your score for a test case will be between 0 and 1). Your score for the problem will simply be the sum of your scores for the individual test cases.
標簽:
represented
integers
group
items
上傳時間:
2016-01-17
上傳用戶:jeffery