Time of Update: 2018-12-04
1.將n劃分成不大於m的劃分法: 1).若是劃分多個整數可以存在相同的: dp[n][m]= dp[n][m-1]+ dp[n-m][m] dp[n][m]表示整數 n 的劃分中,每個數不大於 m 的劃分數。 則劃分數可以分為兩種情況: a.劃分中每個數都小於 m,相當於每個數不大於 m- 1, 故劃分數為 dp[n][m-1]. b.劃分中有一個數為 m. 那就在 n中減去 m ,剩下的就相當於把 n-m 進行劃分, 故劃分數為
Time of Update: 2018-12-04
給定整數集合S,找一個最大的d,使得a+b+c=d,且a,b,c,d是S中不同元素。拆成 a+b=d-c ,算出所以a+b並排序,然後枚舉d,c,在二分尋找d-c。注意結果取d,c中的大者。#include <iostream>#include<cstdio>#include <cmath>#include <algorithm>using namespace std;int a[1005];struct bz{int x,y,ss;}sum[10
Time of Update: 2018-12-04
這樣搜尋不錯:#include<stdio.h>#include<math.h>int a[10000];int dd;//用dd來儲存最小差 void fun(int sum,int cur,int m,int i) { if (i<m)//最多選m個 { //假設cur為其中一個的分得的和,如,sum=67,cur=35,t1=-3; int t1=sum-2*cur; if (t1<0)
Time of Update: 2018-12-04
P89#include <iostream>#include <cstdio>#include <cstring>#include <algorithm> using namespace std;struct AB{int a,b,sum;}bz[500005];int cmp(AB x,AB y){return x.a<y.a;}int OK(int key,int end){int
Time of Update: 2018-12-04
#include <iostream>#include <cstring>#include <algorithm>using namespace std;struct point{int x,y;};int cmp1 (point A,point B)// 按y排序 { return A.y < B.y || (A.y == B.y && A.x < B.x); } int cmp2(point A,point B)////
Time of Update: 2018-12-04
考慮一維的情況,轉化為二維:枚舉 第i行到第j行,然後求出每一列i行到j行的和,拿這些數當一維求即可! #include <stdio.h>#include <string.h>int map[102][102];int main(){ int i,j,k,m,t,r,c,max,temp,cc=0; scanf("%d",&t); while(t--) {cc++; scanf("%d%d",&r,&c);
Time of Update: 2018-12-04
這樣會逾時:#include <iostream>#include<cstdio>#include<cstring>using namespace std;int a[500005];int main(void){ int t,i,j,x; memset(a,0,sizeof(a)); for(i=4;i<=500000;i++) {for(j=2;j*j<i;j++) if(i%j==0) a[i]+=j+i/j;
Time of Update: 2018-12-04
二維數組,高精度加法,兩個大數比較大小……二維數組,高精度加法,兩個大數比較大小……#include<iostream>#include<string.h>using namespace std;char a[600][150]={"0","1","2"};void add(char s1[],char s2[],char a[])//大數加法{ int i,j,k,sum=0;
Time of Update: 2018-12-04
提交不過,自己測試對了,以後再看看#include <iostream>#include <string>#include <cmath>using namespace std;void chenn(string &a,string b)//a=a*b{ int i,j,k,l,sum,c[410]={0}; l=a.length()+b.length(); for(i=b.length()-1;i>=0;i--)
Time of Update: 2018-12-04
六中情況: 1->22->11->33->12->33->2#include <iostream>#include <cstring>#include <string>#include <algorithm>#include <cmath>#include <queue>using namespace std;struct shuibei{int x,y,z,step;}e;int v1,
Time of Update: 2018-12-04
☆硬幣問題 描述 Description 有n種硬幣,面值為別為a[1],a[2],a[3]……a[n],每種都有無限多。給定非負整數s,可以選取多少個硬幣使得面值和恰好為s?輸出硬幣數目最小值和最大值 輸入格式 Input Format 第1行n第2行s第3到n+2行為n種不同的面值 輸出格式 Output Format 第1行為最小值第2行為最大值 範例輸入 Sample Input [複製資料] 36123 範例輸出
Time of Update: 2018-12-04
主要求出第n個迴文數是幾(s)位元組成的,然後求出是s位元這類迴文數的第幾個(k),然後s位元的迴文數的首個加上k-1即可;#include <iostream>#include <string> using namespace std;long long mi(long long w){long long sum=1;while(w--) sum*=10;return sum;} int main(int argc, char *argv[]){long long n,
Time of Update: 2018-12-04
用d[i][j]表示將第i種花擺在a[i][j]位置上,則d[i][j]=cost[i][j]+d[i-1][k] (k<j)枚舉k即可#include <iostream>using namespace std;int d[105][105],a[105][105];int main(int argc, char *argv[]){int i,j,k,n,m,ans;while(cin>>n>>m){for(i=1;i<=n;i++)for(j=
Time of Update: 2018-12-04
//方法1:#include <iostream>#include <cstdio>#include <map>#include <string>#include <cstring>#include <algorithm>using namespace std;struct compute{int zl,jg,pz;}d[1005];int init[1005],n,w,Count;map<string,int>
Time of Update: 2018-12-04
#include <iostream>#include <cstring>#include <cstdio>using namespace std;int n,m,a[62505],b[62505],d[62505];int binary(int left,int right,int key){while(left<right){int mid=(left+right)>>1;if(d[mid]>key) right=mid;else
Time of Update: 2018-12-04
#include <iostream>#include<cstdio> using namespace std;struct DNA{int a,c,g,t;}d[1005];int main(int argc, char *argv[]){int t,n,m,i,j,ans,max;char s[1005];cin>>t;while(t--){ scanf("%d%d",&n,&m); for(i=0;i<m;i++)d[i].a=
Time of Update: 2018-12-04
dp[i]表示從從頭到i劃分最少的迴文串數。 dp[i]=dp[j-1]+1 {i<=j,i-j是迴文}#include <iostream>#include <cstring>#include <cstdio>using namespace std;char s[1005];int dp[1005];int OK(int i,int j){ for(int k=0;k<=(j-i)/2;k++)if(s[i+k]!=s[j-k])
Time of Update: 2018-12-04
不要以為簡單就不仔細,你會知道錯的!!#include <iostream>#include <cstdio>using namespace std;int n,L[10005],R[10005],a[10005],dp[10005];int binary(int i,int j,int key){ while(i<j){ int mid=(i+j)/2;if(dp[mid]==key) return mid;if(dp[mid]>key)
Time of Update: 2018-12-04
#include<iostream>#include<cstring>#include<cstdio>#include<string>#include<cmath>#include<algorithm>using namespace std;#define CLR(arr, what) memset(arr, what, sizeof(arr))const int N = 500002;const int M = 25000
Time of Update: 2018-12-04
解釋詳見:訓練指南P50#include <iostream>#include <algorithm>using namespace std;int up[1005][1005],lef[1005][1005],righ[1005][1005];char a[1005][1005]; int main(){int t,m,n,ans,lo,ro,i,j;char s;cin>>t;while(t--){cin>>m>>n;for(i=0