COGS 304. [NOI2001] 方程的解数 meet in the middle
来源:互联网 发布:dns使用的端口号为 编辑:程序博客网 时间:2024/06/13 07:55
304. [NOI2001] 方程的解数
时间限制:3 s 内存限制:64 MB问题描述
已知一个n元高次方程:
其中:x1, x2, …,xn是未知数,k1,k2,…,kn是系数,p1,p2,…pn是指数。且方程中的所有数均为整数。
假设未知数1≤ xi ≤M, i=1,,,n,求这个方程的整数解的个数。
输入文件
文件的第1行包含一个整数n。第2行包含一个整数M。第3行到第n+2行,每行包含两个整数,分别表示ki和pi。两个整数之间用一个空格隔开。第3行的数据对应i=1,第n+2行的数据对应i=n。
输出文件
文件仅一行,包含一个整数,表示方程的整数解的个数。
输入样例
31501 2-1 21 2
输出样例
168
约束条件
1<=n<=6;1<=M<=150;
方程的整数解的个数小于2^31。
★本题中,指数Pi(i=1,2,……,n)均为正整数。
裸的meet in the middle
注意一下:
OJ的样例是错的!
上面这个是我改好的
#include<cmath>#include<ctime>#include<cstdio>#include<cstring>#include<cstdlib>#include<iostream>#include<algorithm>#include<iomanip>#include<vector>#include<string>#include<bitset>#include<queue>#include<set>#include<map>using namespace std;typedef long long ll;typedef double db;inline int read(){int x=0,f=1;char ch=getchar();while(ch<'0'||ch>'9'){if(ch=='-')f=-1;;ch=getchar();}while(ch<='9'&&ch>='0'){x=(x<<1)+(x<<3)+ch-'0';ch=getchar();}return x*f;}void print(int x){if(x<0)putchar('-'),x=-x;if(x>=10)print(x/10);putchar(x%10+'0');}const int N=3375010;int n,M,num[2],st[9],K[9],P[9];ll res[2][N];ll lala;void dfs(int step,int aim){if(step>aim){if(aim<n){num[0]++;for(int i=1;i<=aim;++i)res[0][num[0]]+=1ll*K[i]*ll(pow(db(st[i]),db(P[i])));}else{num[1]++;for(int i=n/2+1;i<=n;++i)res[1][num[1]]+=1ll*K[i]*ll(pow(db(st[i]),db(P[i])));}return ;}for(int i=1;i<=M;++i)st[step]=i,dfs(step+1,aim);}int main(){n=read();M=read();register int i,j,k;for(i=1;i<=n;++i){K[i]=read();P[i]=read();}dfs(1,n>>1);dfs(n/2+1,n);if(!num[0]){res[0][++num[0]]=0;}sort(res[0]+1,res[0]+1+num[0]);sort(res[1]+1,res[1]+1+num[1]);k=j=num[1];ll ans=0;for(i=1;i<=num[0];++i){while(j&&res[1][j]+res[0][i]>0)j--;while(k&&res[1][k]+res[0][i]>=0)k--;ans+=j-k;}cout<<ans<<endl;return 0;}/*31501 2-1 21 2178*/
阅读全文
0 0
- COGS 304. [NOI2001] 方程的解数 meet in the middle
- NOI2001方程的解数 (DFS技巧:meet in the middle)(非哈希)
- 【meet in the middle深度优先搜索】 NOI2001方程的解数
- [NOI2001]方程的解数
- 【noi2001】方程的解数
- Meet in the middle
- Meet-in-the-middle思想的一些应用
- Meet-in-the-middle思想的一些应用
- 编程竞赛技巧:Meet in the middle
- [LA2965][建模][Meet in the middle]侏罗纪
- 一道“暴力题” (meet in the middle)
- 《精通SOA》连载:7.7.1 在RAD中创建meet-In-the-Middle的Mapping关系
- 【meet in the middle】的几个例题【BZOJ 4800】&【SPOJ ABCDEF】
- [Codeforces 674F] Bears and Juice dp+巧妙的meet in the middle优化
- LA 2965 (map的正确使用方法+MEET IN THE MIDDLE)
- SRM 572 D1L2:EllysBulls,Brute Force,meet in the middle
- 【A*/Meet in the middle/BFS模板】8数码问题
- 【TC-SRM461Div1】Fencing Garden【Meet In The Middle】【二分】
- Mysql查询条件加引号与不加引号的区别
- jquery $.proxy使用
- 生成不重复的随机数
- Spring Boot工程结构推荐
- Thymeleaf 模板
- COGS 304. [NOI2001] 方程的解数 meet in the middle
- 算法思想
- 每天一道LeetCode-----合并两个/多个有序链表为一个新链表
- mybatis关联查询结果集
- 请关注我的英文主页!
- 如何快速转载CSDN中的博客
- STM32的SPI使用注意
- 5. Longest Palindromic Substring
- Unity lightmap shader