UVALive - 4260 Fortune Card Game (DP&状态转移)好题
2016-05-16 11:23
603 查看
UVALive - 4260
Fortune Card Game
SubmitStatus
Description
![](https://icpcarchive.ecs.baylor.edu/components/com_onlinejudge/images/button_pdf.png)
A popular card game called ``fortune" is getting popular in country X. Fig. 1 shows one of the cards. In each card, a positive integer number (20 in the figure) is listed as the address of the card. A symbol is drawn beside the address. There are five kinds
of symbols, which are listed below the card. For convenience, let each symbol be represented by an English letter from `A'-`E'. The bottom of a card contains another number called ``next fortune number."
![](http://7xjob4.com1.z0.glb.clouddn.com/4283ed41dcfb41e19e5514a40323eb19)
[align=center]Figure 1: A sample fortune card and symbols. [/align]
In a set of fortune cards, many cards can have same address; that is, address 20 is not limited to appear only in one card. However, there will be no cards that are identical, i.e., no two cards with same address, symbol, and next fortune number.
The fortune card game is played as follows. A player starts with cards that have address 1. The goal of the game is trying to complete a ``spell" that is composed by the symbols. For example, let a spell be ``BADDAD". In the first move, the player
will look for cards that have address 1 with a star symbol (which matches `B' in the spell). The next fortune numbers of these cards are the new addresses for the next move. The player can select one card to advance to a new address x. The selected
card is then put back to the cards for next move but the fortune number is written down.
Let the example be continued. In the next move, the player needs to look for the cards that have new address x with the cross symbol (which matches the second `A' in the spell). Again, the player selects one card to advance to another new address.
This procedure continues until the spell ``BADDAD" is completed. Once the player completes a spell, he wins a score by adding all the next fortune numbers of the selected card, which have been written down.
Given a spell and a set of fortune cards, please output the maximum score that can be played in this card game.
Technical Specification
N - the number of test cases,
N
![](http://7xjob4.com1.z0.glb.clouddn.com/52924ff46420864cc52d14690cd99213)
10 .
C - the number of cards,
C
![](http://7xjob4.com1.z0.glb.clouddn.com/52924ff46420864cc52d14690cd99213)
800 .
L - the length of a spell,
L
![](http://7xjob4.com1.z0.glb.clouddn.com/52924ff46420864cc52d14690cd99213)
150 .
Input
Test data begins with an integer N which is the number of test cases. Each test case begins with an integer
C , which is the number of cards. Following the number
C is C lines of card information. Each card is represented by (Address Symbol NextF ortuneNumber). The address and next fortune number are between 1 and 800. The symbols are capital letters
from ` A' to ` E'. The last line of a test case is a spell. The spell is a string composed by capital letters from `
A' to ` E'. The length of the spell ( L ) is less than 150.
Output
For each test case, please output the maximum score that can be collected for each test case.
Sample Input
Sample Output
Fortune Card Game
Time Limit: 3000MS | Memory Limit: Unknown | 64bit IO Format: %lld & %llu |
Description
![](https://icpcarchive.ecs.baylor.edu/components/com_onlinejudge/images/button_pdf.png)
A popular card game called ``fortune" is getting popular in country X. Fig. 1 shows one of the cards. In each card, a positive integer number (20 in the figure) is listed as the address of the card. A symbol is drawn beside the address. There are five kinds
of symbols, which are listed below the card. For convenience, let each symbol be represented by an English letter from `A'-`E'. The bottom of a card contains another number called ``next fortune number."
[align=center]Figure 1: A sample fortune card and symbols. [/align]
In a set of fortune cards, many cards can have same address; that is, address 20 is not limited to appear only in one card. However, there will be no cards that are identical, i.e., no two cards with same address, symbol, and next fortune number.
The fortune card game is played as follows. A player starts with cards that have address 1. The goal of the game is trying to complete a ``spell" that is composed by the symbols. For example, let a spell be ``BADDAD". In the first move, the player
will look for cards that have address 1 with a star symbol (which matches `B' in the spell). The next fortune numbers of these cards are the new addresses for the next move. The player can select one card to advance to a new address x. The selected
card is then put back to the cards for next move but the fortune number is written down.
Let the example be continued. In the next move, the player needs to look for the cards that have new address x with the cross symbol (which matches the second `A' in the spell). Again, the player selects one card to advance to another new address.
This procedure continues until the spell ``BADDAD" is completed. Once the player completes a spell, he wins a score by adding all the next fortune numbers of the selected card, which have been written down.
Given a spell and a set of fortune cards, please output the maximum score that can be played in this card game.
Technical Specification
N - the number of test cases,
N
10 .
C - the number of cards,
C
800 .
L - the length of a spell,
L
150 .
Input
Test data begins with an integer N which is the number of test cases. Each test case begins with an integer
C , which is the number of cards. Following the number
C is C lines of card information. Each card is represented by (Address Symbol NextF ortuneNumber). The address and next fortune number are between 1 and 800. The symbols are capital letters
from ` A' to ` E'. The last line of a test case is a spell. The spell is a string composed by capital letters from `
A' to ` E'. The length of the spell ( L ) is less than 150.
Output
For each test case, please output the maximum score that can be collected for each test case.
Sample Input
2 7 1 A 2 1 A 3 2 A 3 2 B 4 2 B 5 3 A 3 3 B 4 AAAAB 6 1 A 2 1 B 2 1 A 3 1 B 3 2 A 3 2 B 3 AB
Sample Output
16 5
//题意:
给你n张卡片,每张卡片有三个属性,ai 卡片的索引,ci 卡片的符号,bi 卡片的价值,现在给你一串字符串,让你根据这个字符串求出这个字符串的最大价值,找最大价值是有要求的:
你所拿的这张卡片的价值应为下一张卡片的索引值。
//思路:
运用动态规划求最值,dp[i][j]表示第i个字符索引值为j的最大价值那么可以得到状态转移方程为:dp[i][p[j].b]=max(dp[i][p[j].b,dp[i-1][p[j].a]+p[j].b);
有了上面的状态转移方程就可以计算了。
#include<stdio.h> #include<string.h> #include<algorithm> #include<iostream> #define INF 0x3f3f3f3f #define N 810 using namespace std; struct zz { int a; char c; int b; }p ; int dp ; char s[210]; int main() { int t,n; int i,j; scanf("%d",&t); while(t--) { scanf("%d",&n); for(i=1;i<=n;i++) scanf("%d %c %d",&p[i].a,&p[i].c,&p[i].b); scanf("%s",s); int len=strlen(s); memset(dp,-INF,sizeof(dp)); dp[0][1]=0; for(i=1;i<=len;i++) { for(j=1;j<=n;j++) { if(s[i-1]==p[j].c) { dp[i][p[j].b]=max(dp[i][p[j].b],dp[i-1][p[j].a]+p[j].b); } } } int ans=0; for(i=1;i<=n;i++) { ans=max(ans,dp[len][i]); } printf("%d\n",ans); } return 0; }
相关文章推荐
- 使用Jenkins+xcodebuild搭建iOS的持续集成系统
- 在 vSphere Distributed Switch 上编辑 VMkernel 配置
- 【iCore3 双核心板_ uC/OS-III】例程七:信号量——任务同步
- Hadoop和大数据:60款顶级开源工具
- 关于智能码控门禁系统项目的二维码验证问题
- HDU-1166- 敌兵布阵(线段树 插点问线)
- iOS代码量统计
- 添加vMotion网络的VMkernel端口组
- 让EditText不能自动获取焦点
- Android Sqlite 数据库版本更新
- Unknown system variable 'tx_read_only'
- 八大排序之插入排序
- iReport各块区域的作用
- android 中webview退出当前页面仍然继续播放的问题
- Unity3D -- ScreenToWorldPoint
- 二叉查找树详解
- js关于DOM和BOM
- iOS保持界面流畅的技巧
- iOS如何解决某些方法低版本不支持的问题
- 数组------找零问题