zoj 1503 - One Person "The Price is Right"
2014-09-26 00:42
309 查看
题目:有一个数字让你猜,你有k次机会,并且有k个保险如果猜的低了会高度你低了,
高了会告诉你高了,并且失去一k保险(k=0时猜高了就会失败),现在问你能猜的数字范围。
分析:dp,二维动态规划。按保险k和猜的机会n递增的方向dp。
状态:f(G,L)为有G次猜的机会,L个保险时确定的数字范围(1~N);
转移方程:F(G,L)= G(G-1,L)+ 1 + F(G-1,L-1){ 猜低 + 猜中 + 猜高 };
边界条件:如果没有失败机会的话,只能从1开始向后猜;
说明:(2011-10-03 16:32)。
高了会告诉你高了,并且失去一k保险(k=0时猜高了就会失败),现在问你能猜的数字范围。
分析:dp,二维动态规划。按保险k和猜的机会n递增的方向dp。
状态:f(G,L)为有G次猜的机会,L个保险时确定的数字范围(1~N);
转移方程:F(G,L)= G(G-1,L)+ 1 + F(G-1,L-1){ 猜低 + 猜中 + 猜高 };
边界条件:如果没有失败机会的话,只能从1开始向后猜;
说明:(2011-10-03 16:32)。
#include <iostream> #include <cstdlib> using namespace std; long long F[ 31 ][ 31 ]; int main() { for ( long long i = 0 ; i <= 30 ; ++ i ) F[ i ][ 0 ] = i; for ( int i = 0 ; i <= 30 ; ++ i ) F[ 0 ][ i ] = 0L; for ( int i = 1 ; i <= 30 ; ++ i ) for ( int j = 1 ; j <= 30 ; ++ j ) F[ i ][ j ] = F[ i-1 ][ j ]+F[ i-1 ][ j-1 ]+1; int G,L,C = 1; while ( cin >> G >> L && ( G || L ) ) cout << "Case " << C++ << ": " << F[ G ][ L ] << endl; return 0; }
相关文章推荐
- zoj 1503 One Person "The Price is Right"
- zoj1503-One Person "The Price is Right"
- 1525. One Person "The Price is Right"
- One of the disks in this virtual machine is already in use by a virtual machine or by a snapshot"
- The best way to be "right once" is to have the ability to envision what things are going to look like three weeks, three months
- "There is only one way to do it, the right way” -------Guido van Rossum
- The prefix "tx" for element "tx:advice" is not bound 错误的说明
- PRB: "Requested Registry Access Is Not Allowed" Error Message When ASP.NET Application Tries to Write New EventSource in the Eve
- IT doesn't matter,The right person really matter
- Server Error in '/' Application. Access to the Path Is Denied" error message appears
- Thinking About "OGL 3 & DX 11: The War Is Over
- Tomcat 中 "The value for the useBean class attribute is invalid" 错误的排除
- Sharepoint Error: "This server is not the indexer of this search application"
- The prefix "tx" for element "tx:advice" is not bound 错误的说明
- 有感"Java is not platform-independent, it is the platform"
- (上一篇的问题解决后又遇到的新问题)在eclipse中导入工程后运行任意文件出现"The selection is not within a valid module"
- Debug error:"One or more breakpoints cannot be set and have been disabled.Execution will stop at the beginning of the program."
- "The value for the useBean class attribute is invalid" 错误。
- VS2005智能设备项目的Bug:"The OutputPath property is not set for this project..."
- [Outlook 2007]The error message: "Either there is no default mail client or the current mail client cannot fulfill the messaging