折半搜索,map会T所以用hash表来存状态

#include<iostream>
#include<cstdio>
#include<map>
using namespace std;
const int N=10,mod=739391;
int n,m,k[N],p[N],w,a[155][N],h[1000005],cnt;
long long ans;
map<int,int>mp;
struct qwe
{
int ne,to,va;
}e[4000005];
void update(int x)
{//cerr<<x<<endl;
int u=(x%mod+mod)%mod,fl=0;
for(int i=h[u];i;i=e[i].ne)
if(e[i].to==x)
{
e[i].va++;//cerr<<e[i].va<<endl;
fl=1;
break;
}
if(!fl)
{
cnt++;
e[cnt].ne=h[u];
e[cnt].to=x;
e[cnt].va=1;
h[u]=cnt;
}
}
int ques(int x)
{//cerr<<x<<endl;
int u=(x%mod+mod)%mod;
for(int i=h[u];i;i=e[i].ne)
if(e[i].to==x)
return e[i].va;
return 0;
}
int ksm(int a,int b)
{
int r=1;
while(b)
{
if(b&1)
r=r*a;
a=a*a;
b>>=1;
}
return r;
}
void dfs(int w,int v)
{
if(!w)
{
update(v);
return;
}
for(int i=1;i<=m;i++)
dfs(w-1,v+k[w]*a[i][w]);
}
void dfs2(int w,int v)
{
if(!w)
{
ans+=ques(-v);
return;
}
for(int i=1;i<=m;i++)
dfs2(w-1,v+k[n-w+1]*a[i][n-w+1]);
}
int main()
{
scanf("%d%d",&n,&m);
for(int i=1;i<=n;i++)
scanf("%d%d",&k[i],&p[i]);
for(int i=1;i<=m;i++)
for(int j=1;j<=n;j++)
a[i][j]=ksm(i,p[j]);
int w=n/2;
dfs(w,0);
dfs2(n-w,0);
printf("%lld\n",ans);
return 0;
}

poj 1186 方程的解数【折半dfs+hash】的更多相关文章

  1. POJ 1186 方程的解数

    方程的解数 Time Limit: 15000MS   Memory Limit: 128000K Total Submissions: 6188   Accepted: 2127 Case Time ...

  2. 计蒜客 方程的解数(DFS)

    问题描述 输出格式 输出一行,输出一个整数,表示方程的整数解的个数. 样例输入 - 样例输出 #include <stdio.h> #include <string.h> #i ...

  3. Meet in the middle算法总结 (附模板及SPOJ ABCDEF、BZOJ4800、POJ 1186、BZOJ 2679 题解)

    目录 Meet in the Middle 总结 1.算法模型 1.1 Meet in the Middle算法的适用范围 1.2Meet in the Middle的基本思想 1.3Meet in ...

  4. 计蒜客 方程的解数 dfs

    题目: https://www.jisuanke.com/course/2291/182237 思路: 来自:https://blog.csdn.net/qq_29980371/article/det ...

  5. NOI2001 方程的解数

    1735 方程的解数 http://codevs.cn/problem/1735/ 2001年NOI全国竞赛  时间限制: 5 s  空间限制: 64000 KB     题目描述 Descripti ...

  6. [ NOI 2001 ] 方程的解数

    \(\\\) \(Description\) 已知一个 \(N\) 元高次方程: \[ k_1x_1^{p_1}+k_2x_2^{p_2}+...+k_nx_n^{p_n}=0 \] 要求所有的 \( ...

  7. cogs 304. [NOI2001] 方程的解数(meet in the middle)

    304. [NOI2001] 方程的解数 ★★☆   输入文件:equation1.in   输出文件:equation1.out   简单对比时间限制:3 s   内存限制:64 MB 问题描述 已 ...

  8. P5691 [NOI2001]方程的解数

    题意描述 方程的解数 求方程 \(\sum_{i=1}^{n}k_ix_i^{p_i}=0(x_i\in [1,m])\) 的解的个数. 算法分析 远古 NOI 的题目就是水 类似于这道题. 做过这道 ...

  9. CH 2401 - 送礼 - [折半DFS+二分]

    题目链接:传送门 描述 作为惩罚,GY被遣送去帮助某神牛给女生送礼物(GY:貌似是个好差事)但是在GY看到礼物之后,他就不这么认为了.某神牛有N个礼物,且异常沉重,但是GY的力气也异常的大(-_-b) ...

随机推荐

  1. C#中使用byte[]数据,生成Bitmap

    /// <summary> /// 使用byte[]数据,生成256色灰度 BMP 位图 /// </summary> /// <param name="ori ...

  2. Intel processor brand names-Xeon,Core,Pentium,Celeron----Pentium

    http://en.wikipedia.org/wiki/Pentium Pentium From Wikipedia, the free encyclopedia     This article ...

  3. python的pexpect模块

    Pexpect 是 Don Libes 的 Expect 语言的一个 Python 实现,是一个用来启动子程序,并使用正则表达式对程序输出做出特定响应,以此实现与其自动交互的 Python 模块. P ...

  4. Mysql 数据库中间件

    读写分离:简单的说是把对数据库读和写的操作分开对应不同的数据库服务器,这样能有效地减轻数据库压力,也能减轻io压力.主数据库提供写操作,从数据库提供读操作,其实在很多系统中,主要是读的操作.当主数据库 ...

  5. win10安装Anaconda+TensorFlow+配置PyCharm

    其实很简单,我这里也只是记录一下而已. 第一大坑:anaconda必须安装4.2以前的版本,不能安装4.3以后的 版本:满满的血泪史 因为我们需要安装自带的python必须是3.5,才可以调用Tens ...

  6. CarbonData

    CarbonData http://carbondata.apache.org/ Apache顶级项目CarbonData应用实践与2.0新技术规划介绍_搜狐科技_搜狐网 https://www.so ...

  7. Yii2 behaviors中verbs access的一些理解

    public function behaviors() { return ArrayHelper::merge(parent::behaviors(), [ 'verbs' => [ 'clas ...

  8. android user用户版本提高adb权限【转】

    本文转载自:http://blog.csdn.net/liyongming1982/article/details/14108111 有的user用户版本的log 不全,且push/pull某些文件或 ...

  9. UVA11624 Fire! —— BFS

    题目链接:https://vjudge.net/problem/UVA-11624 题解: 坑点:“portions of the maze havecaught on fire”, 表明了起火点不唯 ...

  10. Adobe 官方公布的 RTMP 规范

    原文:  http://blog.csdn.net/defonds/article/details/17534903 RTMP 规范中文版 PDF 下载地址 译序:本文是为截至发稿时止最新 Adobe ...