CF332D.Theft of Blueprints

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Insurgents accidentally got hold of the plan of a top secret research polygon created on a distant planet for the needs of the Galaxy Empire. The insurgents suppose that this polygon is developing new deadly weapon. The polygon consists of nn missile silos connected by bidirectional underground passages. The passages are linked to laboratories where research is conducted. Naturally, the passages are guarded severely: the passage between silos ii and jj is patrolled by ci,jc_{i,j} war droids.

The insurgents studied the polygon plan and noticed its unusual structure. As it turned out, for any kk -element set of silos SS there is exactly one silo that is directly connected by a passage with each silo from SS (we'll call this silo adjacent with SS ). Having considered that, the insurgents decided to act as follows:

  1. they choose a kk -element set of silos SS ;
  2. a group of scouts lands from the air into each silo from SS ;
  3. each group moves along the corresponding passage to the silo, adjacent with SS (as the scouts move, they check out the laboratories and watch for any signs of weapon blueprints);
  4. in the silo, adjacent with SS , the groups get on the ship and fly away.

The danger of the operation is the total number of droids that patrol the passages through which the scouts will go. The danger of the operation obviously only depends on the way to choose set SS . The insurgents haven't yet decided on the exact silos to send the scouts to. However, they already want to start preparing the weapons for the scout groups. To do that, the insurgents need to know the mathematical average of the dangers of the operations that correspond to all possible ways to choose set SS . Solve this problem to help the insurgents protect the ideals of the Republic!

输入格式

The first line contains two integers nn and kk ( 2<=n<=20002<=n<=2000 , 1<=k<=n11<=k<=n-1 ) — the number of silos and the number of scout groups, correspondingly. The next n1n-1 lines describe the polygon plan: the ii -th of these lines contains nin-i integers ci,i+1,ci,i+2,...,ci,nc_{i,i+1},c_{i,i+2},...,c_{i,n} — the number of droids that patrol the corresponding passages (- 1<=ci,j<=1091<=c_{i,j}<=10^{9} ; if ci,j=c_{i,j}= - 11 , then silos ii and jj don't have a passage between them). All passages are bidirectional, that is, we can assume that ci,j=cj,ic_{i,j}=c_{j,i} . No passages connect a silo with itself. It is guaranteed that the polygon plan meets the conditions of the problem statement.

输出格式

Print the average danger of the scouting operation, rounded down to an integer. Note that at the given limits the answer to the problem always fits into the standard integer 64-bit data type.

Please do not use the %lld specifier to write 64-bit integers in С++. It is preferred to use the cout stream or the %I64d specifier.

输入输出样例

  • 输入#1

    6 1
    -1 -1 -1 8 -1
    -1 5 -1 -1
    -1 -1 3
    -1 -1
    -1
    

    输出#1

    5
    
  • 输入#2

    3 2
    10 0
    11
    

    输出#2

    14
    

说明/提示

In the first sample there are 6 one-element sets of silos. For sets 1{1} , 5{5} the operation danger will equal 8, for sets 3{3} , 6{6} — 3, for sets 2{2} , 4{4} — 5. The mathematical average equals .

In the second sample there are 3 two-elements sets of silos: 1,3{1,3} (danger equals 21), 1,2{1,2} (danger equals 11), 2,3{2,3} (danger equals 10). The average operation danger equals .

首页