上一页 1 2 3 4 5 6 7 8 9 10 ··· 17 下一页
摘要: 这道题虽然是道YY题,就两行代码,但挺锻炼思维的#include <iostream> #include <cstdio> using namespace std; int main() { int n; while(cin>>n&&n) { if(n%2==0) cout<<"No Solution!"<<endl; else cout<<n-1<<endl; } return 0; } 阅读全文
posted @ 2013-03-24 14:03 LJ_COME!!!!! 阅读(112) 评论(0) 推荐(0)
摘要: dp之,状态转移方程比较好理解。学到的东西就是可以通过拓展状态的维数,是思路更加简便,严谨#include <iostream> #include <cstdio> using namespace std; const int maxn=1500+10; int head[maxn][15],d[maxn]; int f[maxn][2]; int n; int min(int a,int b) { return a<b?a:b; } void dp(int x) { if(d[x]==0) { f[x][0]=0; f[x][1]=1; return; } fo 阅读全文
posted @ 2013-03-22 21:40 LJ_COME!!!!! 阅读(108) 评论(0) 推荐(0)
摘要: 从最优解的结果考虑,f(s)表示节点集合s最多可分为多少组,如果s中节点及其所连节点的并集是节点的全集的话说明s至少可分为一组,反之,可知f(s)=0,当确定s至少可分一组时,可知其最优解的组成肯定是s的某一子集s0(s0中各节点及其联接的节点的并集为全集且s0只能分成一组否则会造成浪费)+(s-s0),那么f(s)=max{f(s-s0)+1.#include <iostream> #include <cstdio> using namespace std; const int maxn=20; int n; int p[maxn]; int f[1<<m 阅读全文
posted @ 2013-03-20 14:25 LJ_COME!!!!! 阅读(138) 评论(0) 推荐(0)
摘要: 完全背包问题的变形,79ms,不过此题需要一个优化,就是把背包实际容量除以1000,不优化的话,数据量很大,会超时。刚开始优化直接定义成double,除了之后再乘,wa,因为有浮点误差,后来考虑了一下,改为了int,ac#include <iostream> #include <cstdio> using namespace std; int amount; int d,year; int intere[11]; int v[11]; int f[100000]; int main() { int N; cin>>N; while(N--) { cin> 阅读全文
posted @ 2013-03-19 18:54 LJ_COME!!!!! 阅读(152) 评论(0) 推荐(0)
摘要: 解题思路看了官方的思路,就是前缀和的思想,做题时也想到了用前缀和,但没想到怎么才能提高效率,一点一点进步吧做完后,各种失误,各种wa,经过n个时间的查错,终于ac啦#include <iostream> #include <cstdio> using namespace std; const int maxn=100000+3; int s[maxn][35]; int a[maxn][35]; int head[maxn],nexvt[maxn]; int n,k; int main() { while(~scanf("%d%d",&n,& 阅读全文
posted @ 2013-03-16 11:05 LJ_COME!!!!! 阅读(268) 评论(0) 推荐(0)
摘要: 又是LIS,又没看出来,写了一个O(n2),用滚动数组优化的算法,超时,瞥了一眼discuss看到了LIS这个字眼,一想,还果然可转化为LIS,而且还这么明显,居然没看出来#include <iostream>#include <cstdio>#include <algorithm>using namespace std;const int maxn=40000+10;const int inf=200000000;int num[maxn];int f[maxn],d[maxn];int main(){ int n,p; scanf("%d&qu 阅读全文
posted @ 2013-03-14 21:26 LJ_COME!!!!! 阅读(111) 评论(0) 推荐(0)
摘要: 无限感慨啊,这道题半年前就做过,无限wa就放弃了,今天又重做这题,依旧没变无限wa,只不过这次敲了20分钟就完了,代码也简洁了,哈希函数直接自己构造的,比之前熟练了,然后检查,历经一个小时之后,才发现把'eh'当成了'en',改后ac,300ms,然后再翻出之前的代码,果然是同样的错误,回想起半年前的那一整个下午,真是欲哭无泪啊#include <iostream>#include <cstdio>#include <cstring>using namespace std;const int maxn=100000+3;int 阅读全文
posted @ 2013-03-13 21:23 LJ_COME!!!!! 阅读(104) 评论(0) 推荐(0)
摘要: dp状态转移方程:d(i,j)=sum(i,j)-min{d(i+1,j),d(i+2,j)...d(j,j),d(i,j-1),d(i,j-2)...d(i,i),0}可化为d(i,j)=sum(i,j)-min{f(i+1,j),g(i,j-1),0}#include <iostream>#include <cstring>#include <cstdio>using namespace std;const int maxn=100+10;int arr[maxn];int f[maxn][maxn],d[maxn][maxn],s[maxn],g[ma 阅读全文
posted @ 2013-03-13 19:36 LJ_COME!!!!! 阅读(124) 评论(0) 推荐(0)
摘要: 递推,把问题转化为具有相同问题的子问题,通过子问题最后所剩余的编号,退出此问题所剩余的编号#include <iostream> using namespace std; const int maxn=10000+10; int f[maxn]; int main() { int n,k,m; while(~scanf("%d %d %d",&n,&k,&m)) { if(!n&&!k&&!m) break; f[1]=0; for(int i=2;i<=(n-1);i++) f[i]=(f[i-1] 阅读全文
posted @ 2013-03-12 19:51 LJ_COME!!!!! 阅读(126) 评论(0) 推荐(0)
摘要: 最短路的应用,只不过路径的权值从单一的长度变成了各种耗费时间的和#include <iostream> #include <cstdio> #include <string.h> using namespace std; const int maxn=300+10; const int maxm=(50000+10)*2; const int inf=200000000; int head[maxn],dis[maxn],vis[maxn],pre[maxn],re[maxn],ans[maxn]; int e[maxm],nextv[maxm],cost[ 阅读全文
posted @ 2013-03-12 19:48 LJ_COME!!!!! 阅读(146) 评论(0) 推荐(0)
上一页 1 2 3 4 5 6 7 8 9 10 ··· 17 下一页