• 博客园logo
  • 会员
  • 周边
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • YouClaw
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
HaibaraAi
博客园    首页    新随笔    联系   管理    订阅  订阅

Uva 省赛傻逼题 I

fuck,我TM什么眼神,总能让自己把自己的代码打错,然后一个小时以上的找错误!

Problem I

Time limit: 2.000 seconds

 

Interesting Calculator

There is an interesting calculator. It has 3 rows of button.

Row 1: button 0, 1, 2, 3, ..., 9. Pressing each button appends that digit to the end of the display.

Row 2: button +0, +1, +2, +3, ..., +9. Pressing each button adds that digit to the display.

Row 3: button *0, *1, *2, *3, ..., *9. Pressing each button multiplies that digit to the display.

Note that it never displays leading zeros, so if the current display is 0, pressing 5 makes it 5 instead of 05. If the current display is 12, you can press button 3, +5, *2 to get 256. Similarly, to change the display from 0 to 1, you can press 1 or +1 (but not both!).

Each button has a positive cost, your task is to change the display from x to y with minimum cost. If there are multiple ways to do so, the number of presses should be minimized.

Input

There will be at most 30 test cases. The first line of each test case contains two integers x and y(0<=x<=y<=105). Each of the 3 lines contains 10 positive integers (not greater than 105), i.e. the costs of each button.

Output

For each test case, print the minimal cost and the number of presses.

Sample Input

12 256
1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1
12 256
100 100 100 1 100 100 100 100 100 100
100 100 100 100 100 1 100 100 100 100
100 100 10 100 100 100 100 100 100 100

Output for the Sample Input

Case 1: 2 2
Case 2: 12 3

The Ninth Hunan Collegiate Programming Contest (2013)
Problemsetter: Rujia Liu
Special Thanks: Feng Chen, Md. Mahbubul Hasan

 

 1 #pragma comment(linker, "/STACK:1024000000,1024000000")
 2 #include <map>
 3 #include <queue>
 4 #include <vector>
 5 #include <string>
 6 #include <cstdio>
 7 #include <cstring>
 8 #include <iostream>
 9 #include <algorithm>
10 using namespace std;
11 #define maxn 100005
12 #define ll long long
13 #define INF 0x7fffffff
14 int c[maxn];
15 int dp[maxn];
16 int a[4][11];
17 int k,n,t;
18 int dfs(int m)
19 {
20     if(dp[m]!=INF)return dp[m];
21     for(int i=1;i<10;i++)if(m-i>=0){int d=dfs(m-i);if(dp[m]>d+a[1][i]||dp[m]==d+a[1][i]&&c[m]>c[m-i]+1){dp[m]=d+a[1][i];c[m]=c[m-i]+1;}}
22     for(int i=1;i<10;i++)if(m%i==0){int d=dfs(m/i);if(dp[m]>d+a[2][i]||dp[m]==d+a[2][i]&&c[m]>c[m/i]+1){dp[m]=d+a[2][i];c[m]=c[m/i]+1;}}
23     if(m/10>=0){int d=dfs(m/10);if(dp[m]>d+a[0][m%10]||dp[m]==d+a[0][m%10]&&c[m]>c[m%10]+1){dp[m]=d+a[0][m%10];c[m]=c[m/10]+1;}}
24     return dp[m];
25 }
26 int main(){
27     int m;
28     int cas=1;
29     while(~scanf("%d%d",&n,&t)){
30         memset(c,0,sizeof c);
31         for(int i=0;i<=t;i++)dp[i]=INF;
32         for(int i=0;i<3;i++)
33         for(int j=0;j<10;j++)scanf("%d",&a[i][j]);
34         dp[0]=a[2][0];dp[n]=0;c[0]=1;c[n]=0;
35         printf("Case %d: ",cas++);
36         dfs(t);
37         printf("%d %d\n",dp[t],c[t]);
38     }
39     return 0;
40 }
View Code 2013-10-15 11:18:11

 

posted @ 2013-10-15 11:17  HaibaraAi  阅读(115)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2026
浙公网安备 33010602011771号 浙ICP备2021040463号-3