编程介的小学生 2017-08-27 08:02 采纳率: 20.5%
浏览 658
已采纳

Imperishable Night

It's the eve of the Harvest Moon Festival in Gensokyo when Flandre Scarlet senses that something is wrong with the moon. It appears that the moon has been replaced by a fake moon. Someone must freeze time and find the real moon to ensure a full moon on the night of the festival. Remilia Scarlet tells her that she must go into the Bamboo Forest of the Lost (迷いの竹林) to investigate and gain enough points to remedy this.

二小姐
Flandre sets off immediately. When she arrives at the entry of the Bamboo Forest of the Lost, she finds that there are n different parts. According to Remilia, there are two kinds of mysterious halidom, ITEM and TIME, that will increase Flandre's points:

When Flandre is at the entry, she can choose any path she hasn't choosed before and collects all ITEM and TIME there, then goes back to the entry.
There are two values, IV (ITEM Value) and TV (TIME Value) relating to how many points Flandre can gain when she collect a piece of ITEM or a piece of TIME.
The initial IV, TV and point of Flandre are all 0.
When she chooses a new part, her IV and TV and point keep the same as the end of he previous collection.
In parti, there are xi pieces of ITEM with value ai and yi pieces of TIME with value bi.
When she collects a piece of ITEM, her point will increase IV (point += IV), and her TV will increase ai (TV += ai) immediately as well.
when she collects a piece of TIME, her point will increase TV (point += TV), and her IV will increase bi (IV += bi) immediately as well.
Obviously, Flandre's IV and TV will be changing when she is collecting ITEM and TIME, thus the order of collection is important. Morever, the order of the parts she chooses is crucial too. Flandre should gain as many points as possible. Your task is to calculate the maximal point Flandre can gain.

Input

The input contains multiple test cases (no more than 100). The first line of each case is an integer n (1 ≤ n ≤ 15), indicating the number of parts of the forest. Then follows n lines, the i-th (1 ≤ i ≤ n) of them contains 4 integers ai, bi, xi, yi (0 ≤ ai, bi ≤ 20, 0 ≤ xi, yi ≤ 30), as described above.

Output

For each case, output the maximal point Flandre can gain in a single line.

Sample Input

1
1 2 1 1
3
2 2 2 2
2 2 2 2
2 2 2 2
Sample Output

2
72

  • 写回答

1条回答

  • devmiao 2017-09-10 04:50
    关注
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 安卓adb backup备份应用数据失败
  • ¥15 eclipse运行项目时遇到的问题
  • ¥15 关于#c##的问题:最近需要用CAT工具Trados进行一些开发
  • ¥15 南大pa1 小游戏没有界面,并且报了如下错误,尝试过换显卡驱动,但是好像不行
  • ¥15 没有证书,nginx怎么反向代理到只能接受https的公网网站
  • ¥50 成都蓉城足球俱乐部小程序抢票
  • ¥15 yolov7训练自己的数据集
  • ¥15 esp8266与51单片机连接问题(标签-单片机|关键词-串口)(相关搜索:51单片机|单片机|测试代码)
  • ¥15 电力市场出清matlab yalmip kkt 双层优化问题
  • ¥30 ros小车路径规划实现不了,如何解决?(操作系统-ubuntu)