SPOJ AMR10I Dividing Stones --DFS
2024-09-21 00:03:48
题意:给n个石头,分成一些部分(最多n部分,随便分),问分完后每部分的数量的乘积有多少种情况。
分析:可以看出,其实每个乘积都可以分解为素数的乘积,比如乘积为4,虽然可以分解为4*1,但是更可以分解为2*2*1,所以就可以枚举素因子来分解,dfs即可。
代码:
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <set>
#define ll long long
using namespace std;
#define N 100007 int prime[] = {, , , , , , , , , , , , , , , , , , , };
int n,p;
set<ll> ans; void dfs(int ind,int now,ll num)
{
ans.insert(num);
if(now < prime[ind])
return;
dfs(ind,now-prime[ind],num*prime[ind]%p); //分解这个
dfs(ind+,now,num); //不分解这个
} int main()
{
int t;
scanf("%d",&t);
while(t--)
{
scanf("%d%d",&n,&p);
ans.clear();
dfs(,n,);
printf("%d\n",ans.size());
}
return ;
}
最新文章
- Wiki语料处理
- 多个div居中显示
- 团队项目——站立会议 DAY8
- 15个IT技术人员必须思考的问题
- DELPHI7在WIN8和WIN10下安装和运行
- 15个实用的jQuery技术
- AM335x(TQ335x)学习笔记——挂载Ramdisk
- Android NDK 环境搭建 + 测试例程
- 10. Regular Expression Matching
- python_求1-2+3-4+......-100的值
- Hibernate进阶知识点必备
- C. New Year and Rating 差分方程 思维
- luogu准备复习(学习)题单
- ";Loading a plug-in failed The plug-in or one of its prerequisite plug-ins may be missing or damaged and may need to be reinstalled";
- RDD内存迭代原理(Resilient Distributed Datasets)---弹性分布式数据集
- Linux添加防火墙、iptables的安装和配置(亲测)
- 打包python为可执行文件时报错R6034解决方案
- 配置consul为windows服务
- git untrack file
- git服务器-------》用户免密git操作