博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
uva 10404 - Bachet's Game(DP)
阅读量:4035 次
发布时间:2019-05-24

本文共 1900 字,大约阅读时间需要 6 分钟。

1、

2、题目大意:

给n个石子,有m种取法,每次可以取m堆中的某一堆,Stan先取,Ollie再取,谁取到最后一个石子,谁获胜,最后输出获胜者即可

乍一看挺简单,不过还是没想出来怎么做,看网上的代码

dp[i]表示当前剩余i个石子时Stan的获胜状态,1表示获胜,0表示输了,

状态转移方程:if(i>=stone[j] && dp[i-stone[j]]==0) dp[i]=1;

3、题目:

Problem B: Bachet's Game

Bachet's game is probably known to all but probably not by this name. Initially there are n stones on the table. There are two players Stan and Ollie, who move alternately.  Stan always starts. The legal moves consist in removing at least one but not more thank stones from the table.  The winner is the one to take the last stone.

Here we consider a variation of this game.  The number of stones that can be removed in a single move must be a member of a certain set of m numbers.  Among the m numbers there is always 1 and thus the game never stalls.

Input

The input consists of a number of lines.  Each line describes one game by a sequence of positive numbers. The first number isn <= 1000000 the number of stones on the table; the second number is m <= 10 giving the number of numbers that follow; the last m numbers on the line specify how many stones can be removed from the table in a single move.

Input

For each line of input, output one line saying either Stan winsor Ollie wins assuming that both of them play perfectly.

Sample input

20 3 1 3 821 3 1 3 822 3 1 3 823 3 1 3 81000000 10 1 23 38 11 7 5 4 8 3 13999996 10 1 23 38 11 7 5 4 8 3 13

Output for sample input

Stan winsStan winsOllie winsStan winsStan winsOllie wins

Problem Setter: Piotr Rudnicki

 

4、
#include
#include
int stone[15];int dp[1000005];int main(){ int n,m; while(scanf("%d%d",&n,&m)!=EOF) { for(int i=0;i
=stone[j] && dp[i-stone[j]]==0) { dp[i]=1; break; } } } if(dp[n]==1) printf("Stan wins\n"); else printf("Ollie wins\n"); } return 0;}

转载地址:http://gqddi.baihongyu.com/

你可能感兴趣的文章
PowerDesigner:导入SQL脚本
查看>>
PowerDesigner使用教程
查看>>
eclipse中使用Ctrl+Alt+↑或↓时屏幕旋转的问题
查看>>
freemarker 数字格式化(金额格式化)
查看>>
eclipse中Deployment Assembly选项设置说明
查看>>
maven项目报:Project configuration is not up-to-date with pom.xml. Run Maven->Update Project
查看>>
pom.xml中maven-compiler-plugin插件配置的使用
查看>>
使用maven-war-plugin 对Maven项目进行动态打包
查看>>
spring定时任务配置
查看>>
Log4j2 配置笔记(Eclipse+maven+SpringMVC)
查看>>
java设计模式之简单工厂模式
查看>>
struts2中constant参数设置
查看>>
Struts2中struts.multipart.maxSize设置
查看>>
CheckStyle插件在eclipse中的安装及配置
查看>>
PowerDesigner 导入数据库建表SQL脚本生成物理模型
查看>>
idea的xml配置中url显示:URI is not registered ( Setting | Project Settings | Schemas and DTDs )
查看>>
如何修改源码>重新打包>替换源文件
查看>>
@Slf4j注解的使用
查看>>
SpringBoot通过配置devtools实现热部署
查看>>
springboot+springsecurity+jwt进行系统权限开发
查看>>