#P1336. 最佳课题选择

    ID: 333 远端评测题 1000ms 125MiB 尝试: 0 已通过: 0 难度: 5 上传者: 标签>动态规划,dp福建省历届夏令营

最佳课题选择

Description

Matrix67 must submit nn papers to his teacher next month. The content of each paper can be chosen from mm topics. Since the number of topics is limited, Matrix67 has to reuse some topics. The time required to complete papers on different topics varies. Specifically, for topic ii, if Matrix67 plans to write a total of xx papers, then the total time needed for that topic is Ai×xBiA_i \times x^{B_i} time units. Given AiA_i and BiB_i for each topic, please help Matrix67 determine how to choose the topics for the nn papers so that the total time is minimized.

Input Format

The first line contains two integers nn and mm, representing the number of papers to complete and the number of available topics, respectively.
The next mm lines each contain two integers. On the ii-th line, the two numbers represent the time coefficient AiA_i and the exponent BiB_i corresponding to topic ii.

Output Format

Output the minimum total time required to complete nn papers.

10 3
2 1
1 2
2 1

19

Hint

Sample Explanation:
Choose topic 1 for 44 papers, topic 3 for 55 papers, and topic 2 for the remaining 11 paper. The total time is 2×41+1×12+2×51=8+1+10=192\times4^1+1\times1^2+2\times5^1=8+1+10=19. It can be proven that there is no better plan with total time less than 1919.

Constraints:
For 30%30\% of the testdata, n10n \le 10, m5m \le 5.
For 100%100\% of the testdata, 1n2001 \le n \le 200, 1m201 \le m \le 20, 1Ai1001 \le A_i \le 100, 1Bi51 \le B_i \le 5.

Translated by ChatGPT 5