编程介的小学生 2016-12-16 08:04 采纳率: 20.3%
浏览 888
已采纳

Telecom

Description

ACM-Telecom provides communication services for international telephone calls. Cost of calling a country (call rates), varies from one to another. The company maintains the rates in a cost table mapping the country codes to call rates. Upon receiving a call, an automatic system determines the country code by looking at the leftmost digits in the 8-digit dialed number and charges the client according to the call rate of that country. More precisely, the automatic system maintains a list of country codes sorted in decreasing order. Upon receiving a call, the system starts from the top of the list and checks if the country code is a prefix of the dialed number. The first country code satisfying this property is considered as the destination of the call and the client is charged according to the call rate of that country. Note that the cost table covers every possible 8-digit number dialed, i.e., every dialed number matches with some country code in the table. Given the relatively high number of rows in the cost table and the increasing number of calls, the computation of call rates has become a quite lengthy process. Your task is to find a new cost table with the minimum number of rows such that the computed call costs for every possible (8-digit) dialed number are the same as before.
Input

The first line of the input contains a single integer t (1 ≤ t ≤ 20) which is the number of test cases in the input. Each test case starts with a line containing a single integer N(1 ≤ N ≤ 1000) which is the number of rows in the cost table. Following the first line, there are N lines of the form code cost where code is an integer between 1 and 9999 inclusive, and cost (1 ≤ cost ≤ 100) is a positive integer which is the cost rate of the calls to the country code. There are no two lines with the same country code in a test case.
Output

For each test case, there is one line in the output containing the minimum number of rows of the table required to compute the costs correctly.
Sample Input

1
12
331 4
33 4
335 4
1 1
2 2
3 3
4 4
5 5
6 6
7 7
8 8
9 9
Sample Output

10

  • 写回答

1条回答 默认 最新

  • threenewbee 2016-12-16 15:47
    关注
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 access多表提取相同字段数据并合并
  • ¥20 基于MSP430f5529的MPU6050驱动,求出欧拉角
  • ¥20 Java-Oj-桌布的计算
  • ¥15 powerbuilder中的datawindow数据整合到新的DataWindow
  • ¥20 有人知道这种图怎么画吗?
  • ¥15 pyqt6如何引用qrc文件加载里面的的资源
  • ¥15 安卓JNI项目使用lua上的问题
  • ¥20 RL+GNN解决人员排班问题时梯度消失
  • ¥60 要数控稳压电源测试数据
  • ¥15 能帮我写下这个编程吗