上一页 1 2 3 4 5 6 7 8 9 10 ··· 26 下一页
摘要: 这个题是计算不同子序列的和;spoj上的那个同名的题是计算不同子序列的个数;其实都差不多;计算不同子序列的个数使用dp的思想;从头往后扫一遍如果当前的元素在以前没有出现过,那么dp[i]=dp[i-1]*2+1;不然找到最右边的这个元素出现的位置j;dp[i]=d[i]*2-dp[j];spoj代码:#include#include#include#define mod 1000000007using namespace std;char s[100005];int pos[100005];int biao[30];int dp[100005];int main(){ int t,n; ... 阅读全文
posted @ 2013-12-11 22:47 Yours1103 阅读(162) 评论(0) 推荐(0) 编辑
摘要: 这个题我想到要用kmp找到循环节;但是后面的我就不会做了;看到题解才知道是字符串的最小表示;#include#include#include#define maxn 100005using namespace std; char s[maxn*2];int next[maxn]; void kmp(int n){ int j=0; for(int i=2;i0&&s[i]!=s[j+1])j=next[j]; if(s[i]==s[j+1])++j; next[i]=j; }} void MinimumRepresentation(int n){ ... 阅读全文
posted @ 2013-12-11 22:41 Yours1103 阅读(149) 评论(0) 推荐(0) 编辑
摘要: 因为每个元素都是移动到比它小1位的元素的后面;这样的话以后的一定就可以把他们两个打包;所以用这种方法最多扫一遍就可以了;但是最小的那个数要不要移动呢?如果最小的数后面的数都是升序的,那么一直扫到最小的那个数就行了;不然的话要完整的扫一遍;这个地方我没想清楚,WA的好惨,最后还是看到斌哥的代码才恍然大悟的;#include#include#define maxn 100005using namespace std;int n,t,m;int num[maxn],f[maxn],r[maxn],cnt[maxn]; bool cmp(const int &x,const int & 阅读全文
posted @ 2013-12-11 22:38 Yours1103 阅读(151) 评论(0) 推荐(0) 编辑
摘要: 这是一个动态规划的题;当初想到要用dp,但是一直想不到状态转移的方程;题解上的原话: 动态规划,设 g[i]表示总结点数为 i 的方案种数,另设 f[i][j]表示各个孩子的总结点数为i,孩子的个数为 j 的方案数,那么有 g[i+1]=f[i][1]+f[i][2]+...+f[i][k],相当于添加一个根节点之后变成完整的树,同时要把有 1 个孩子,2个孩子, ……,k 个孩子的情况都考虑进去。对于 f[i][j]的求解可以用类似背包的方法去做,在求解的时候也会用到 g[1], g[2], ..., g[i]的值,根据前面的那个 g[i+1]的表达式来看,这些 g[]已经在前面算出来了。. 阅读全文
posted @ 2013-12-11 22:32 Yours1103 阅读(135) 评论(0) 推荐(0) 编辑
摘要: 这个题目其实很简单,可惜当时比赛的时候看到出的人少,以为有trick,就和队友扯淡去了;因为每个数总是被相邻的数影响,所以往前往后扫两遍就行了; 1 #include 2 #include 3 #include 4 #define maxn 100005 5 using namespace std; 6 7 int num[maxn]; 8 int num1[maxn]; 9 int num2[maxn];10 11 int main()12 {13 int t;14 int n,d;15 scanf("%d",&t);16 while(t--)17 ... 阅读全文
posted @ 2013-12-11 22:30 Yours1103 阅读(175) 评论(0) 推荐(1) 编辑
摘要: 用set写真是轻松愉快;#include#include#include#includeusing namespace std;setst;int ans;int main(){ int n,x; st.insert(-99999999); st.insert(99999999); scanf("%d",&n); for(int i=0; i0) { ans+=y; st.insert(x); } } } printf("%d\n",a... 阅读全文
posted @ 2013-12-05 18:14 Yours1103 阅读(309) 评论(0) 推荐(0) 编辑
摘要: 很直观的一个gauss题;用的是以前用过的一个模板;#include#include#include#include#define maxn 12#define eps 0.00001using namespace std;double matrix[15][15];double ans[15];void exchange_col(int p1,int p2,int n){ double t; int i; for(int i=0; ifabs(matrix[p][i])) p=j; if(p!=i) exch... 阅读全文
posted @ 2013-12-04 21:27 Yours1103 阅读(215) 评论(0) 推荐(0) 编辑
摘要: 先对a排序,a相等的话就对b排序;维护一个栈,每次取栈的头两个,和当前的直线相比较;如果当前的直线把头第一个屏蔽,就将他出栈,一直到不能屏蔽为止;代码:#include#include#include#define maxn 500005using namespace std;int st[maxn],top;int num[maxn];struct line{ int a,b; int id; bool operatort.b; else return a1) { if(check(i,st[top-1],st[top-2]... 阅读全文
posted @ 2013-12-04 18:50 Yours1103 阅读(169) 评论(0) 推荐(0) 编辑
摘要: 图上的最小的染色方案;学习了陈丹绮的论文: MCS算法#include#define maxn 10005#define maxm 2000005using namespace std;int head[maxn],next[maxm],edge[maxm];int cnt;int d[maxn],f[maxn];void add(int a,int b){ edge[++cnt]=b; next[cnt]=head[a]; head[a]=cnt;}int main(){ int n,m,x,y; scanf("%d%d",&n,&m); while(m- 阅读全文
posted @ 2013-12-04 17:05 Yours1103 阅读(163) 评论(0) 推荐(0) 编辑
摘要: spfa+dp;刚刚开始一直想不通怎么判断他是否换了道;后来才知道,将那个时间段打包,找出这段时间内的最短路;真是太奇妙了!#include#include#include#include#define inf 1e6using namespace std;int map[22][22];int pass[22][105];int d[22],inq[22];int n,m,k,e;int dp[22];int spfa(int s,int t){ queueq; for(int i=1; id[u]+map[u][i])) { ... 阅读全文
posted @ 2013-12-03 23:44 Yours1103 阅读(169) 评论(0) 推荐(0) 编辑
上一页 1 2 3 4 5 6 7 8 9 10 ··· 26 下一页