UVA 111 History Grading(动态规划 LIS)
2013-04-29 20:25
477 查看
HistoryGrading
Considerahistoryexaminwhichstudentsareaskedtoputseveralhistoricaleventsintochronologicalorder.Studentswhoorderalltheeventscorrectlywillreceivefullcredit,buthowshouldpartialcreditbeawardedtostudentswhoincorrectlyrankoneormoreofthehistoricalevents?
Somepossibilitiesforpartialcreditinclude:
1pointforeacheventwhoserankmatchesitscorrectrank
1pointforeacheventinthelongest(notnecessarilycontiguous)sequenceofeventswhichareinthecorrectorderrelativetoeachother.
Forexample,iffoureventsarecorrectlyordered1234thentheorder1324wouldreceiveascoreof2usingthefirstmethod(events1and4arecorrectlyranked)andascoreof3usingthesecondmethod(eventsequences124and134arebothinthecorrectorderrelativetoeachother).
Inthisproblemyouareaskedtowriteaprogramtoscoresuchquestionsusingthesecondmethod.
Background
ManyproblemsinComputerScienceinvolvemaximizingsomemeasureaccordingtoconstraints.Considerahistoryexaminwhichstudentsareaskedtoputseveralhistoricaleventsintochronologicalorder.Studentswhoorderalltheeventscorrectlywillreceivefullcredit,buthowshouldpartialcreditbeawardedtostudentswhoincorrectlyrankoneormoreofthehistoricalevents?
Somepossibilitiesforpartialcreditinclude:
1pointforeacheventwhoserankmatchesitscorrectrank
1pointforeacheventinthelongest(notnecessarilycontiguous)sequenceofeventswhichareinthecorrectorderrelativetoeachother.
Forexample,iffoureventsarecorrectlyordered1234thentheorder1324wouldreceiveascoreof2usingthefirstmethod(events1and4arecorrectlyranked)andascoreof3usingthesecondmethod(eventsequences124and134arebothinthecorrectorderrelativetoeachother).
Inthisproblemyouareaskedtowriteaprogramtoscoresuchquestionsusingthesecondmethod.
TheProblem
GiventhecorrectchronologicalorderofneventsViewCode#include<iostream> #include<stdio.h> #include<string.h> #include<map> usingnamespacestd; map<int,int>s;//map函数用来记录事件对应的时间顺序 inta[30];//用来表示学生答案的最终序列 intdp[30]; intmain(){ intn,x,i,j,max; scanf("%d",&n); s.clear(); for(i=1;i<=n;i++){ scanf("%d",&x); s[i]=x; } //这里的输入很特别,如果用while(1)会超时,这样先输入一个x,再接下来的输入中少输入一个即可 while(scanf("%d",&x)!=EOF){ a[x]=s[1]; for(i=2;i<=n;i++){ scanf("%d",&x); a[x]=s[i]; } memset(dp,0,sizeof(dp)); dp[1]=1; max=1; for(i=2;i<=n;i++){ for(j=i-1;j>=1;j--) if(a[i]>a[j]&&dp[j]>dp[i]) dp[i]=dp[j]; dp[i]++; if(dp[i]>max) max=dp[i]; } printf("%d\n",max); } return0; }
相关文章推荐
- UVa 111 - History Grading 最长递增子序列 LIS
- UVa 111 - History Grading 最长递增子序列 LIS
- [动态规划]UVA111 - History Grading
- UVA 111 - History Grading(动态规划)
- uva 111 History Grading(动态规划——最长公共子序列)
- UVa 111|History Grading|动态规划|最长上升子序列
- UVa 111 History Grading (简单DP,LIS或LCS)
- (DP6.1.4.1)UVA 111 History Grading(最长递增子序列LIS 的LCS 解法)
- UVA 111 History Grading
- UVa 111 - History Grading
- uva 111 - History Grading (dp, LCS)
- uva 111 History Grading
- UVA - 111 History Grading(LCS最长公共子序列)
- UVA - 111 History Grading
- UVa 111 - History Grading
- UVA - 111 History Grading
- UVa Problem 111 - History Grading
- UVA 111 History Grading
- UVA 111 History Grading (最长公共子序列)
- UVA 111 - History Grading