当前位置:网站首页>P1057 passing game (DP)

P1057 passing game (DP)

2021-08-10 08:05:13 wx6110fa547fd20

P1057 Passing games (DP)

  Subject portal

The question :n Individual pass , Seek from 1 Start passing , Pass on m Second pass to 1 Number of alternatives .

Ideas :
 Insert picture description here

AC Code :
sol1: The way to take the mold :

#include<cstdio>
int a[35][35];
int main(){
	int n,m;
	scanf("%d%d",&n,&m);
	a[0][0]=1;
	for(int i=0;i<m;i++)
		for(int j=0;j<n;j++)
			a[i+1][(j-1+n)%n]+=a[i][j],a[i+1][(j+1)%n]+=a[i][j];
	printf("%d\n",a[m][0]);
	return 0;
}

      
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.

sol2: Special judgement 1 and n

#include<cstdio>
int a[35][35];
int main(){
	int n,m;
	scanf("%d%d",&n,&m);
	a[0][1]=1;
	for(int i=1;i<=m;i++)
		for(int j=1;j<=n;j++)
		{
			if(j==1) a[i][j]=a[i-1][n]+a[i-1][2];
			else if(j==n) a[i][j]=a[i-1][n-1]+a[i-1][1];
			else a[i][j]=a[i-1][j-1]+a[i-1][j+1];
		}
	printf("%d\n",a[m][1]);
	return 0;
}

      
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.

版权声明
本文为[wx6110fa547fd20]所创,转载请带上原文链接,感谢
https://chowdera.com/2021/08/20210810080205626U.html

随机推荐