摘要: 学习了一下一下map的迭代器,刷一题裸题练习一下:#include #include #include #include using namespace std; int main() { int n; while(scanf("%d",&n)&&n) { int max=0; map mp; map::iterator p; string s; for(int i=0;i>s; mp[s]++; } ... 阅读全文
posted @ 2014-01-22 19:25 forever97 阅读(149) 评论(0) 推荐(0) 编辑
摘要: 题解:将背包总量分为两份,之后多重背包即可#include #include int f[300000],w[1000],t[1000];int main(){ int n; while(scanf("%d",&n),n>=0) { int v=0; for(int i=1; i=k*w[j]; i--) if (f[i-w[j]]+w[j]>f[i]) f[i]=f[i-w[j]]+w[j]; printf("%d %d\n",v-f[v/2],f[v/2]); } return 0;} 阅读全文
posted @ 2014-01-22 15:17 forever97 阅读(128) 评论(0) 推荐(0) 编辑
摘要: 题解:完全背包问题(背包要装满)#include using namespace std; int e,b,n; int f[10005]; int p[505],w[505]; int main(){ int t; scanf("%d",&t); while(t--){ scanf("%d%d",&e,&b); e=b-e; scanf("%d",&n); for(int i=1;i<=n;i++)scanf("%d%d",&p[i],&w[i]); for( 阅读全文
posted @ 2014-01-22 13:49 forever97 阅读(168) 评论(0) 推荐(0) 编辑
摘要: 题解:简单动态规划#include #include using namespace std;int f[21][1001];int max(int a,int b){return(a>b?a:b);}int main(){ int t; scanf("%d",&t); while(t--) { int n,m; scanf("%d%d",&n,&m); for(int i=1; i<=n; i++) for(int j=1; j<=m; j++) scanf("%d",&f[i][j 阅读全文
posted @ 2014-01-22 13:06 forever97 阅读(162) 评论(0) 推荐(0) 编辑
摘要: 题解:我们把每一秒可以走到的地方标注起来 5 4 5 6 3 4 5 6 7 2 3 4 5 6 7 8 1 2 3 4 5 6 7 8 90 1 2 3 4 5 6 7 8 9 10很显然,这是一座数塔,f[i,j]只可以从f[i+1,j],f[i+1,j-1],f[i+1,j+1]中来,那么就是简单的DP了。#include #include using namespace std;int f[100001][13];int max(int a,int b){return(a>b?a:b);}int main(){ int n; while(scanf("%... 阅读全文
posted @ 2014-01-22 10:44 forever97 阅读(134) 评论(0) 推荐(0) 编辑
摘要: 题解:经典数塔问题#include #include using namespace std;#define rep(i,m,n) for(int i=m;ib?a:b);}int main(){ int t; scanf("%d",&t); while(t--) { memset(f,0,sizeof(f)); int n; scanf("%d",&n); rep(i,1,n)rep(j,1,i)scanf("%d",&f[i][j]); for(int i=n-1; i; i--)rep(j,1,... 阅读全文
posted @ 2014-01-22 09:56 forever97 阅读(124) 评论(0) 推荐(0) 编辑
摘要: 题解:用优先队列,建立小根堆,然后每次取出最小的,将其乘上题目要求的数字再加入优先队列,至于重复的问题,用映射来解决#include #include #include #include using namespace std; #define MAXI 5843 priority_queue, greater > Q; long long hn[MAXI], l; map exi; void init() { long long tmp; l = 1; Q.push(1); while (l<MAXI) ... 阅读全文
posted @ 2014-01-22 09:15 forever97 阅读(158) 评论(0) 推荐(0) 编辑
摘要: 题解:最长上升子序列的应用,按w升序,s降序排列后进行DP找最长序列,用pre[]数组记录该点的前驱,从而打印路径#include #include using namespace std; struct mouse{ int w,s,id; bool operatorm.s); } }m[1005]; int d[1005],pre[1005],ms=1,ans[1005]; void solve(){ d[0]=-1; int head=0; for(int i=1;im[j].w&&m[i].sd[t]... 阅读全文
posted @ 2014-01-22 08:09 forever97 阅读(170) 评论(0) 推荐(0) 编辑
摘要: 题解:最长上升子序列的扩展应用,不过,加上的是当前值,而不是1/*最长上升子序列扩展应用*/#include using namespace std;int n,d[1050],a[1050];int dp(){ int rs=0; for(int i=1;ia[j]&&a[i]+d[j]>d[i])d[i]=a[i]+d[j]; if(d[i]>rs)rs=d[i]; } return rs;}int main(){ while(scanf("%d",&n),n) { for(int i=1;i<=n;i++)scanf(&quo 阅读全文
posted @ 2014-01-22 08:04 forever97 阅读(141) 评论(0) 推荐(0) 编辑
摘要: 题解:裸的LCS/*LCS*/#include #include using namespace std;int f[1000][1000]={0};int main(){ string a,b; while(cin>>a>>b) { int m,n; n=a.length(); m=b.length(); memset(f,0,sizeof(f)); for (int i=0; if[i+1][j])?f[i+1][j+1]=f[i][j+1]:f[i+1][j+1]=f[i+1][j]; ... 阅读全文
posted @ 2014-01-22 07:59 forever97 阅读(106) 评论(0) 推荐(0) 编辑
摘要: 题目大意:求出数列的最大子段和,并且说明是从第几项至第几项。题解1:简单贪心。#include #define rep(i,n) for(int i=1;iusing namespace std;int a[100005],s[100005],num[100005];int T,n,m,st,ed... 阅读全文
posted @ 2014-01-22 07:54 forever97 阅读(158) 评论(0) 推荐(0) 编辑
摘要: 题解:构建Trie图 由图可知,设f(n)为字符串长度为n时复合条件的字符串个数,以字符串最后一个字符为分界点,当最后一个字符为m时前n-1个字符没有限制,即为f(n-1);当最后一个字符为f时就必须去除最后3个字符是fmf和fff的情况,在考虑最后两个字符为mf和ff的情况,显然不行;最后3个字符为fmf、mmf和fff、mff时只有当最后3个字符为mmf时前n-3个字符没有限制,即为f(n-3),当为mff时第n-3个字符可能为f因而对前n-3个字符串有限制;最后4个字符为fmff和mmff时mmff可行。得到公式f(n)=f(n-1)+f(n-3)+f(n-4) 然后,构建矩阵进行幂.. 阅读全文
posted @ 2014-01-22 07:50 forever97 阅读(204) 评论(0) 推荐(0) 编辑