JOJ 2039: Fire Net III

本文介绍了一种针对特定条件下Blockhouse配置方案的计数算法。该算法通过递推公式结合动态规划思想解决在一个限定大小的地图上不同Blockhouse配置数量的问题,并提供了完整的代码实现。

2039: Fire Net III


StatusIn/OutTIME LimitMEMORY LimitSubmit TimesSolved UsersJUDGE TYPE
stdin/stdout1s10240K22963Standard

Suppose that we have a square city with straight streets. A map of a city is a square board with n rows and n columns, each representing a street or a piece of wall.

A blockhouse is a small castle that has four openings through which to shoot. The four openings are facing North, East, South, and West, respectively. There will be one machine gun shooting through each opening.

Here we assume that a bullet is so powerful that it can run across any distance and destroy a blockhouse on its way. On the other hand, a wall is so strongly built that can stop the bullets.

All the maps are of the same design and only differ in size. Squares on a line from the upper-left corner to the lower-right corner and one square above each square on the line forms the street where blockhouse can be placed.

 

In this problem, we will calculate the number of different configurations of the blockhouse for a certain number of blockhouses. A configuration of blockhouses is legal provided that no two blockhouses are on the same horizontal row or vertical column in a map . In this problem we will consider small square cities (at most 30x30) described above.

Input

The input contains many tests.

Each test cases contains two numbers T (3 <= T <= 30)and C. T is the size of the map and C is the number of blockhouses described above.

Output

For each test cases, output a line containing the number of possible configurations.

Sample Input

3 2
3 1

Sample Output

6
5

 

Problem Source: evilll

 

/分析如下:

设函数f(n,k)中n指的是地图大小,k是指blockhouse的数量,f(n,k)指的是方法数

 

将一个5X5的地图抽象成这样的一个矩阵,可放置的位置用1表示,其他用0表示,这样一个抽象模型就出来 了。从左上角开始放起BLOCKHOUSE,无外就两种可能性。

1.将BLOCK放在左上角,那么就是f剩下(n-1,k-1)

2.第二个不把BLOCKHOUSE放在左上角,那么

所以的话f(n,k)=f(n-1,k-1)+g(n,k)

前者指的就是第一种情况,后者就是第二种情况

g(n,k)也无非两种情况,则g(n,k)=g(n-1,k-1)+f(n-1,k)

所以可以出现递推的情况,可以看出这个是DP了

两个FOR循环,I是从1开始到N,J是从1到K开始,先算G,再算F

for(i=1;i<n;i++)

  for(j=1;j<=k;j++)

  {
        g(n,k)=g(n-1,k-1)+f(n-1,k);

         f(n,k)=f(n-1,k-1)+g(n,k);

   }

现在主要是边界情况的讨论了

主要是i=1,j=1的时候

g(1,1)=g(0,0)+f(0,1);

f(1,1)=f(0,0)+g(1,1)=f(0,0)+f(0,1)+g(0,0);

g(n,k)=g(n-1,k-1)+f(n-1,k)=g(n-1,k-1)+f(n-2,k-1)+g(n-1,k);

 f(n,k)=f(n-1,k-1)+g(n,k)=f(n-1,k-1)+g(n-1,k-1)+f(n-1,k);;

对于边界情况,有:

 for(i=1;i<=30;i++)
 {
   f[i][0]=1;
   g[i][0]=1;
 }

 

 

 

#include<iostream>
int main()
{
 freopen("in.txt","r",stdin);
 freopen("out.txt","w",stdout);
 int i,j,t,c;
 long long  f[50][50],g[50][50];
 memset(f,0,sizeof(f));
 memset(g,0,sizeof(g));
 for(i=1;i<=30;i++)
 {
   f[i][0]=1;
   g[i][0]=1;
 }
 for(i=1;i<=30;i++)
 for(j=1;j<=30;j++)
 {
   if(i==j)
   {
    f[i][j]=1;
    g[i][j]=0;
   }
   else
   if(i<j)
   {
    f[i][j]=0;
    g[i][j]=0;
   }
   else
   {
     g[i][j]=g[i-1][j-1]+f[i-1][j];
     f[i][j]=f[i-1][j-1]+g[i][j];
   }
  }
  while(scanf("%d%d",&t,&c)!=EOF)
  {
     printf("%lld/n",f[t][c]);
  }
 return 0;
}

 

 

 

【四旋翼无人机】具备螺旋桨倾斜机构的全驱动四旋翼无人机:建模与控制研究(Matlab代码、Simulink仿真实现)内容概要:本文围绕具备螺旋桨倾斜机构的全驱动四旋翼无人机展开研究,重点探讨其系统建模与控制策略,结合Matlab代码与Simulink仿真实现。文章详细分析了无人机的动力学模型,特别是引入螺旋桨倾斜机构后带来的全驱动特性,使其在姿态与位置控制上具备更强的机动性与自由度。研究涵盖了非线性系统建模、控制器设计(如PID、MPC、非线性控制等)、仿真验证及动态响应分析,旨在提升无人机在复杂环境下的稳定性和控制精度。同时,文中提供的Matlab/Simulink资源便于读者复现实验并进一步优化控制算法。; 适合人群:具备一定控制理论基础和Matlab/Simulink仿真经验的研究生、科研人员及无人机控制系统开发工程师,尤其适合从事飞行器建模与先进控制算法研究的专业人员。; 使用场景及目标:①用于全驱动四旋翼无人机的动力学建模与仿真平台搭建;②研究先进控制算法(如模型预测控制、非线性控制)在无人机系统中的应用;③支持科研论文复现、课程设计或毕业课题开发,推动无人机高机动控制技术的研究进展。; 阅读建议:建议读者结合文档提供的Matlab代码与Simulink模型,逐步实现建模与控制算法,重点关注坐标系定义、力矩分配逻辑及控制闭环的设计细节,同时可通过修改参数和添加扰动来验证系统的鲁棒性与适应性。
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值