上一页 1 ··· 30 31 32 33 34 35 36 37 38 ··· 61 下一页
摘要: 题目链接:http://gnu.bnu.edu.cn/contest/problem_show.php?pid=4359思路:直接递推就可以了,dp[i][0]表示前i位不含4或者13,且最后一位不为1的个数,dp[i][1]表示前i位不含4或者13,最后一位为1的个数;于是有dp[i][0]=8*dp[i-1][0]+7*dp[i-1][1],dp[i][1]=dp[i-1][0]+dp[i-1][1]; 1 #include<iostream> 2 #include<cstdio> 3 #include<cstring> 4 #include<cm 阅读全文
posted @ 2013-05-31 15:21 ihge2k 阅读(162) 评论(0) 推荐(0) 编辑
摘要: 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2988思路:水题,kruskal求最小生成树之后,直接用总权值减去即可。 1 #include<iostream> 2 #include<cstdio> 3 #include<cstring> 4 #include<algorithm> 5 using namespace std; 6 #define MAXN 222222 7 typedef long long LL; 8 struct Edge{ 9 int u,v,w;10 }edge[MAXN 阅读全文
posted @ 2013-05-31 11:46 ihge2k 阅读(287) 评论(0) 推荐(0) 编辑
摘要: 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3501思路:首先用一下欧拉函数Eluar(n)求一下1-n中与n互质的质因子的个数,然后就要用到下面简单的定理了:如果gcd(n,i)==1,那么就有gcd(n,n-i)==1;于是题目的要求是要求小于n并且与n不互质的所有数的和,这里我们可以先求与n互质的所有数的和为sum=n*(Eular(n)/2)(这里用到了上面的定理。最后所有数的和减去sum即可。 1 #include<iostream> 2 #include<cstdio> 3 #include<cstri 阅读全文
posted @ 2013-05-31 11:04 ihge2k 阅读(378) 评论(0) 推荐(0) 编辑
摘要: 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4360思路:首先就是要寻找最短路了,然后就是要着“LOVE”连着最多的最短路了,这里我们可以用一个二维数组来记录“LOVE”最多的最短路,然后每次spfa更新的时候维护一下就可以了(每当以‘E'结尾是就要num[i][j]++),最后的情况就是要考虑一下特判n==1是的情况了。 1 #include<iostream> 2 #include<cstdio> 3 #include<cstring> 4 #include<algorithm> 5 阅读全文
posted @ 2013-05-30 21:52 ihge2k 阅读(264) 评论(0) 推荐(0) 编辑
摘要: 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4396思路:dist[i][j]表示到顶点i走了k条路所花费的最小时间,为了节省内存,当j>=k时,直接令j=k即可,然后就是二维spfa求最短路了。 1 #include<iostream> 2 #include<cstdio> 3 #include<cstring> 4 #include<algorithm> 5 #include<queue> 6 #include<vector> 7 using namespace 阅读全文
posted @ 2013-05-30 15:53 ihge2k 阅读(353) 评论(0) 推荐(0) 编辑
摘要: 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2608思路:T[n]为1时当且仅当n为某数的平方或者是某数平方的2倍。 1 #include 2 #include 3 #include 4 #include 5 #include 6 using namespace std; 7 typedef long long LL; 8 9 int main(){10 int _case,n,ans,k;11 scanf("%d",&_case);12 while(_case--){13 scanf("%d", 阅读全文
posted @ 2013-05-30 13:07 ihge2k 阅读(227) 评论(0) 推荐(0) 编辑
摘要: 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4293思路:这题dp的状态比较难想,dp[i]表示前i个人最多有多少人说真话,而num[i][j]表示当前人的前面有i个人,后面有j个人的个数,于是有dp[i]=max(dp[i],dp[j]+num[j][n-i])(0<=j<i); 1 #include<iostream> 2 #include<cstdio> 3 #include<cstring> 4 using namespace std; 5 #define MAXN 555 6 int n 阅读全文
posted @ 2013-05-29 22:31 ihge2k 阅读(188) 评论(0) 推荐(0) 编辑
摘要: 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3560思路:dfs判环,这里成环的条件是环中的每个点的出度和入度都为1,因此dfs的时候只须判断的相连的每个点的size()==2即可。ps:为防暴栈手动开栈:#pragma comment(linker,"/STACk:10240000,10240000") 1 #include<iostream> 2 #include<cstdio> 3 #include<cstring> 4 #include<algorithm> 5 #in 阅读全文
posted @ 2013-05-29 19:18 ihge2k 阅读(542) 评论(0) 推荐(0) 编辑
摘要: 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4034思路:要对floyd有深刻的理解才能A这道题,边数最多的情况是每两点之间都有最短的直边相连,故最多为n*(n-1),在每两点都有最短直边相连情况下,我们可以一一删去多余的边,最后就是最终结果。即若dist[i][j]=dist[i][k]+dist[k][j],则i 与 j的这条边可以删去.若dist[i][j]>dist[i][k]+dist[k][j],则说明dist[i][j]并不是最短路,存在矛盾,此时则不存在这样的图,输出impossible。 1 #include 2 #in 阅读全文
posted @ 2013-05-29 18:23 ihge2k 阅读(271) 评论(0) 推荐(0) 编辑
摘要: 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2648思路:map映射,记录一下memory的位置即可。 1 #include 2 #include 3 #include 4 #include 5 #include 6 #include 7 using namespace std; 8 int Point[10010]; 9 10 int main() {11 int n,m,pos,price;12 while(~scanf("%d",&n)) {13 memset(Point,0,sizeof(Point));1. 阅读全文
posted @ 2013-05-28 22:13 ihge2k 阅读(431) 评论(0) 推荐(0) 编辑
上一页 1 ··· 30 31 32 33 34 35 36 37 38 ··· 61 下一页