Itself is Itself(scu1617)
来源:互联网 发布:大数据时代电子商务 编辑:程序博客网 时间:2024/06/05 17:09
1617: Itself is Itself
Time Limit: 6 Sec Memory Limit: 128 MBSubmit: 81 Solved: 18
[Submit][Status][Web Board]
Description
Zuosige always has bad luck. Recently, he is in hospital because of pneumonia. While he is taking his injection, he feels extremely bored. However, clever Zuosige comes up with a new game.
Zuosige writes an integer n and a polynomial function:
P(x) = (a0+a1*x+a2*x2+…+am*xm) mod n.
He wants to know how many subsets of set {0, 1, 2, … , n-2, n-1} satisfies following property: the range of P(x) from the subset is itself. Pay attention to that empty set is also a valid subset.
Input
The first line contains one integer T, indicating the number of test cases.
In one test case, there are two lines.
In the first line, there are two integers n and m (1<=n<=10000, 1<=m<=1000).
In the second line, there m+1 integers. The i-th integer indicating ai-1 (0<=ai<=10000).
Output
For each test case, output an integer in a line indicating the answer. The answer can be very large, so you need just output the answer mod 1e9+7.
Sample Input
23 10 13 11 1
Sample Output
82
HINT
Source
图论(强连通)数圈数n,2^n%mod=
可惜比赛的时候没过。。。
转载请注明出处:http://blog.csdn.net/u010579068
题目链接:http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1617
#include<stdio.h>#include<vector>#include<string.h>using namespace std;#define modd 1000000007const int N= 10005; int n,c[N];int dfn[N],low[N],Stack[N],flag[N],vist[N],num[N],top,deep,tn;vector<int>mapt1[N]; void init(){ for(int i=0;i<=n;i++) { mapt1[i].clear(); dfn[i]=0; num[i]=0; vist[i]=0; } tn=top=deep=0;}int tt;void tarjan(int u){ vist[u]=tt; deep++; dfn[u]=low[u]=deep; Stack[++top]=u; int len=mapt1[u].size(); for(int i=0;i<len;i++) { int v=mapt1[u][i]; if(vist[v]==0) { tarjan(v); if(low[u]>low[v]) low[u]=low[v]; } else if(vist[v]==tt&&low[u]>dfn[v])//注意vist[v]==tt low[u]=dfn[v]; } if(low[u]==dfn[u]) { tn++; while(u!=Stack[top]) { flag[Stack[top]]=tn; num[tn]++;top--; //printf("%d ",Stack[top]); } flag[Stack[top]]=tn; num[tn]++; top--; }}int out[N];int rebuilMap()//用强连通缩点,重新反向建图{ tt=0; for(int i=0;i<n;i++) if(vist[i]==0) { tt++; tarjan(i); } memset(out,0,sizeof(out));//缩点后的图无 有向环 for(int i=0;i<n;i++) { int u=flag[i]; for(int j=0;j<mapt1[i].size();j++) { int v=flag[mapt1[i][j]]; if(u==v) continue; out[u]++; } } int number=0; for(int i=1;i<=tn;i++) if(out[i]==0) number++; return number;}int main(){ int T,m; scanf("%d",&T); while(T--){ scanf("%d%d",&n,&m); for(int i=0;i<=m;i++){ scanf("%d",&c[i]); c[i]%=n; } init(); for(int i=0;i<n;i++) { int ansa=c[0],x=i; for(int j=1;j<=m;j++){ ansa=(ansa+c[j]*x)%n; x=(x*i)%n; } if(i!=ansa) mapt1[i].push_back(ansa); } int number=rebuilMap(); long long ans = 1; for(int i=1;i<=number;i++) ans=(ans*2)%1000000007; printf("%lld\n",ans); } return 0;} /************************************************************** Problem: 1617 User: aking2015 Language: C++ Result: Accepted Time:2756 ms Memory:1628 kb****************************************************************/
- Itself is Itself(scu1617)
- CSU 1617: Itself is Itself(强连通缩点)思想转换到图论
- hdu 4342 History repeat itself(思维)
- Delete/Run scripts itself
- Session blocked itself
- HDU4342 History repeat itself
- in and of itself
- History repeat itself 解题
- hdu_4342 History repeat itself (简单想法题)
- HDU4342——History repeat itself(数学)
- hdu 4342 History repeat itself
- HDU 4342 History repeat itself
- HDOJ 4342 History repeat itself
- HDU 4342 History repeat itself
- Product of Array Exclude Itself
- Product of Array Exclude Itself
- Product of Array Exclude Itself
- HDU 4342 - History repeat itself
- 获取线程ID
- 运行时异常
- 开源项目分类汇总
- C#制表符过滤处理方法
- 【软考】【非对称加密与认证】
- Itself is Itself(scu1617)
- Xcode 6制作动态及静态Framework以及问题的解决
- XMPP聊天软件客户端开发(3)
- 解决Github访问超慢的问题
- Java基本概念与问题(二)
- HDU ACM 4046 Panda 线段树或者树状数组
- 管理之路(三)
- CFStringRef 类型转NSString类型使用 需要使用 __bridge,一定要记住
- Objective-C开发编码规范:4大方面解决开发中的规范性问题