ask恩杰2009机试题目

来源:互联网 发布:js this 编辑:程序博客网 时间:2024/05/16 10:56
 

Given a tree T, each node will have at most two child nodes, T has N nodes. Each node is associated with a number as weight. The weight of a tree is defined as the sum of weights of all its nodes. Given a number M (1 <= M <= N), T' is a sub tree of T that has M nodes. T' also shares the root node with T. Now you are required to find such T' which has the maximum weight.

Example
 
Sample input:
6
12 11 12 14 15 16
1 2
1 3
2 4
2 6
4 5
4
 
First line inputs an integer N, represents the number of nodes in the tree (numbered from 1 to N);
Then the second line inputs n integers represent the weight of each node;
For the next n-1 lines, each line contains two integers, specifying a link from parent -> child;
The last line contains the integer M (1 <= M <= N), which is the number of the nodes in the sub tree.
 
The tree in the sample may like this:
 
        1(12)
        /    /
      2(11)   3(12)
      /    /
    4(14)   6(16)
    /
  5(15)
 
Output:
53
 
The output denotes the max weight of the sub tree with M nodes. The sub tree in the sample will be like (colored in red):
       1(12)
        /    /
  2(11)   3(12)
    /    /

4(14)   6(16)
   /
 5(15)
 
Note
 
       Programming using of C/C or Java.

 

Sentence Similarity Measurement

 

 

Description

 

Given two English sentences, you are required to:

1.       Devise a method to measure the similarity between them, the result score is a value between zero and one. And one means exact match, zero means totally different.

2.       Implement your method with any programming language you familiar with.

3.       Provide a plain text file “README.txt”, where you can describe/analyze your algorithm, list potential improvements, give your comments or anything else.

 

Input/Output

 

Input:

       ./yourProgramName <sentence 1> <sentence 2>

 

Output:

       A score in [0, 1]

 

Example

 

       ./sen_sim “you and me.” “me and you.”

       0.xxx

 

Note

 

1.       Your performance will be rated based on your algorithm performance and content in “README.txt”.

2.       Your method should be reasonable.

3.       Computation complexity of your method should be considered.

4.       If any further improvements, which you can’t implement this time, could be done to your method, you are strongly encouraged to write them down explicitly as a separate section “Potential improvements” in “README.txt”.

5.       Good coding style is desirable.

6.       Comments or feedbacks about this test are welcomed.

 
原创粉丝点击