hihoCoder 1096 Divided Product 微软苏州校招笔试 12月27日
来源:互联网 发布:ubuntu 16.04 unity 编辑:程序博客网 时间:2024/04/29 10:06
这一题的Tag是DP额。。居然用dfs过了。。是数据水了咩(⊙o⊙)…
dfs的方法和枚举组合结果的方法很像。dfs(now,remain,product),now是当前枚举的数的下界(也可以理解成当前位置的前一个数),因为A1~Ak是升序,所以当前位置只要从now往remain枚举即可,remain是当前的数列和还差多少到N。注意乘积product会爆int,要用long long。
#include<iostream>#include<stdio.h>#include<cstdio>#include<stdlib.h>#include<vector>#include<string>#include<cstring>#include<cmath>#include<algorithm>#include<stack>#include<queue>#include<ctype.h>#include<map>#include<time.h>#include<bitset>#include<set>#include<list>using namespace std;//hihocoder 1096 const long long mod=1000000007; int N; int M; long long ans; void dfs(int now,int remain,long long product)//用int product中途乘积可能会溢出 { if(remain==0) { if(product%M==0) { ans++; ans=ans%mod; } } for(int i=now;i<=remain;i++) { dfs(i+1,remain-i,product*i); } }int main(){ // freopen("input.txt","r",stdin); scanf("%d %d",&N,&M); dfs(1,N,1); printf("%d\n",ans); return 0;}
0 0
- hihoCoder 1096 Divided Product 微软苏州校招笔试 12月27日
- [HiHoCoder]#1094 : Lost in the City 微软苏州校招笔试 12月27日
- hihoCoder 1095 HIHO Drinking Game 微软苏州校招笔试 12月27日
- 微软苏州校招笔试 12月27日
- hihoCoder 1107 Shortest Proper Prefix 微软苏州校招笔试 1月17日
- hihoCoder 1103 Colorful Lecture Note 微软苏州校招笔试 1月10日
- hihoCoder 1106 Koch Snowflake 微软苏州校招笔试 1月17日
- 微软苏州校招笔试题目(1月10日)Colorful Lecture Note的解法
- 水水微软苏州校招笔试 1月17日 题解..
- HIHOCODER#1096 : Divided Product
- [微软苏州校招 Hihocoder] Disk Storage
- 微软苏州校招1月3日在线编程题1——constellations
- 微软苏州校招1月3日在线编程题2——Disk Storage
- 微软苏州校招笔试(2016.12):#1091 : Clicker
- hihocoder#1096 : Divided Product(递推DP)
- 【hihocoder】Font Size(微软2016.4校招笔试题)
- 【hihocoder】1237 : Farthest Point ->微软2016校招在线笔试题
- 【2014校招】微软笔试
- JPA与hibernate注解
- 第三周项目3多文件组织
- js 的学习
- 关于在 java 或其他游戏设计中实现屏幕震动
- 最长公共子序列
- hihoCoder 1096 Divided Product 微软苏州校招笔试 12月27日
- 网页的初步认识
- 在CStatic静态文本框中,显示位图,控制位图大小
- android环境
- linux中文乱码,字符集和编码
- 3.8 一些组合变换的例子
- 为函数原型编写函数定义:int my_strcmp(char *s,char *t);
- 最小二乘法拟合直线
- node.js学习笔记之安装详解