-
給定n個(gè)整數(shù)a , a , ,an 1 2 組成的序列。序列中元素i a 的符號(hào)定義為:
ï î
ï í
ì
- <
=
>
=
1 0
0 0
1 0
sgn( )
i
i
i
i
a
a
a
a
符號(hào)平衡問題要求給定序列的最長符號(hào)平衡段的長度L,即:
þ ý ü
î í ì
= + - = å
=
£ £ £
max 1| sgn( ) 0
1
j
k i
i j n k
L j i a 。
例如,當(dāng)n=10,相應(yīng)序列為:1,1,-1,-2,0,1,3,-1,2,-1 時(shí),L=9。
標(biāo)簽:
iuml
61516
icirc
序列
上傳時(shí)間:
2015-10-28
上傳用戶:xaijhqx
-
用遞推法產(chǎn)生正交多項(xiàng)式系,即求alpha[j+1]、beta[j] 入口參數(shù):m是數(shù)據(jù)點(diǎn)數(shù),n是擬合的最高階數(shù), float x[],float y[]是對(duì)應(yīng)縱橫坐標(biāo),出口參數(shù):a[] 是最小二乘擬合參數(shù),alpha[]、beta[]是遞推系數(shù)
標(biāo)簽:
正
多項(xiàng)式
上傳時(shí)間:
2014-01-19
上傳用戶:gyq
-
Floyd-Warshall算法描述
1)適用范圍:
a)APSP(All Pairs Shortest Paths)
b)稠密圖效果最佳
c)邊權(quán)可正可負(fù)
2)算法描述:
a)初始化:dis[u,v]=w[u,v]
b)For k:=1 to n
For i:=1 to n
For j:=1 to n
If dis[i,j]>dis[i,k]+dis[k,j] Then
Dis[I,j]:=dis[I,k]+dis[k,j]
c)算法結(jié)束:dis即為所有點(diǎn)對(duì)的最短路徑矩陣
3)算法小結(jié):此算法簡單有效,由于三重循環(huán)結(jié)構(gòu)緊湊,對(duì)于稠密圖,效率要高于執(zhí)行|V|次Dijkstra算法。時(shí)間復(fù)雜度O(n^3)。
考慮下列變形:如(I,j)∈E則dis[I,j]初始為1,else初始為0,這樣的Floyd算法最后的最短路徑矩陣即成為一個(gè)判斷I,j是否有通路的矩陣。更簡單的,我們可以把dis設(shè)成boolean類型,則每次可以用“dis[I,j]:=dis[I,j]or(dis[I,k]and dis[k,j])”來代替算法描述中的藍(lán)色部分,可以更直觀地得到I,j的連通情況。
標(biāo)簽:
Floyd-Warshall
Shortest
Pairs
Paths
上傳時(shí)間:
2013-12-01
上傳用戶:dyctj
-
out< "please input the number of the nodes"<<endl
cin>>nodesNum
cout<<"please input the graph"<<endl
for( i = 1 i<=nodesNum i++)
for( j = 1 j <= nodesNum j++)
cin>>graph[i][j] */
標(biāo)簽:
lt
the
nodesNum
number
上傳時(shí)間:
2013-11-29
上傳用戶:libinxny
-
程序名:ga_bp_predict.cpp
描述: 采用GA優(yōu)化的BP神經(jīng)網(wǎng)絡(luò)程序,用于單因素時(shí)間
序列的預(yù)測,采用了單步與多步相結(jié)合預(yù)測
說明: 采用GA(浮點(diǎn)編碼)優(yōu)化NN的初始權(quán)值W[j][i],V[k][j],然后再采用BP算法
優(yōu)化權(quán)值
標(biāo)簽:
ga_bp_predict
cpp
程序
BP神經(jīng)網(wǎng)絡(luò)
上傳時(shí)間:
2014-02-18
上傳用戶:冇尾飛鉈
-
動(dòng)態(tài)規(guī)劃的方程大家都知道,就是
f[i,j]=min{f[i-1,j-1],f[i-1,j],f[i,j-1],f[i,j+1]}+a[i,j]
但是很多人會(huì)懷疑這道題的后效性而放棄動(dòng)規(guī)做法。
本來我還想做Dijkstra,后來變了沒二十行pascal就告訴我數(shù)組越界了……(dist:array[1..1000*1001
div 2]...)
無奈之余看了xj_kidb1的題解,剛開始還覺得有問題,后來豁然開朗……
反復(fù)動(dòng)規(guī)。上山容易下山難,我們可以從上往下走,最后輸出f[n][1]。
xj_kidb1的一個(gè)技巧很重要,每次令f[i][0]=f[i][i],f[i][i+1]=f[i][1](xj_kidb1的題解還寫錯(cuò)了)
標(biāo)簽:
動(dòng)態(tài)規(guī)劃
方程
家
上傳時(shí)間:
2014-07-16
上傳用戶:libinxny
-
function [U,center,result,w,obj_fcn]= fenlei(data)
[data_n,in_n] = size(data)
m= 2 % Exponent for U
max_iter = 100 % Max. iteration
min_impro =1e-5 % Min. improvement
c=3
[center, U, obj_fcn] = fcm(data, c)
for i=1:max_iter
if F(U)>0.98
break
else
w_new=eye(in_n,in_n)
center1=sum(center)/c
a=center1(1)./center1
deta=center-center1(ones(c,1),:)
w=sqrt(sum(deta.^2)).*a
for j=1:in_n
w_new(j,j)=w(j)
end
data1=data*w_new
[center, U, obj_fcn] = fcm(data1, c)
center=center./w(ones(c,1),:)
obj_fcn=obj_fcn/sum(w.^2)
end
end
display(i)
result=zeros(1,data_n) U_=max(U)
for i=1:data_n
for j=1:c
if U(j,i)==U_(i)
result(i)=j continue
end
end
end
標(biāo)簽:
data
function
Exponent
obj_fcn
上傳時(shí)間:
2013-12-18
上傳用戶:ynzfm
-
//Euler 函數(shù)前n項(xiàng)和
/*
phi(n) 為n的Euler原函數(shù)
if( (n/p) % i == 0 ) phi(n)=phi(n/p)*i
else phi(n)=phi(n/p)*(i-1)
對(duì)于約數(shù):divnum
如果i|pr[j] 那么 divnum[i*pr[j]]=divsum[i]/(e[i]+1)*(e[i]+2) //最小素因子次數(shù)加1
否則 divnum[i*pr[j]]=divnum[i]*divnum[pr[j]] //滿足積性函數(shù)條件
對(duì)于素因子的冪次 e[i]
如果i|pr[j] e[i*pr[j]]=e[i]+1 //最小素因子次數(shù)加1
否則 e[i*pr[j]]=1 //pr[j]為1次
對(duì)于本題:
1. 篩素?cái)?shù)的時(shí)候首先會(huì)判斷i是否是素?cái)?shù)。
根據(jù)定義,當(dāng) x 是素?cái)?shù)時(shí) phi[x] = x-1
因此這里我們可以直接寫上 phi[i] = i-1
2. 接著我們會(huì)看prime[j]是否是i的約數(shù)
如果是,那么根據(jù)上述推導(dǎo),我們有:phi[ i * prime[j] ] = phi[i] * prime[j]
否則
phi[ i * prime[j] ] = phi[i] * (prime[j]-1)
(其實(shí)這里prime[j]-1就是phi[prime[j]],利用了歐拉函數(shù)的積性)
經(jīng)過以上改良,在篩完素?cái)?shù)后,我們就計(jì)算出了phi[]的所有值。
我們求出phi[]的前綴和
*/
標(biāo)簽:
phi
Euler
else
函數(shù)
上傳時(shí)間:
2016-12-31
上傳用戶:gyq
-
Instead of finding the longest common
subsequence, let us try to determine the
length of the LCS.
Then tracking back to find the LCS.
Consider a1a2…am and b1b2…bn.
Case 1: am=bn. The LCS must contain am,
we have to find the LCS of a1a2…am-1 and
b1b2…bn-1.
Case 2: am≠bn. Wehave to find the LCS of
a1a2…am-1 and b1b2…bn, and a1a2…am and
b b b
b1b2…bn-1
Let A = a1 a2 … am and B = b1 b2 … bn
Let Li j denote the length of the longest i,g g
common subsequence of a1 a2 … ai and b1 b2
… bj.
Li,j = Li-1,j-1 + 1 if ai=bj
max{ L L } a≠b i-1,j, i,j-1 if ai≠j
L0,0 = L0,j = Li,0 = 0 for 1≤i≤m, 1≤j≤n.
標(biāo)簽:
the
subsequence
determine
Instead
上傳時(shí)間:
2013-12-17
上傳用戶:evil
-
經(jīng)典動(dòng)態(tài)壓縮DP,狀態(tài)是f[i][j],表示第i行,以3進(jìn)制j為狀態(tài)。j的位代表一個(gè)格子,只能是:0表示第i行和第i - 1行都沒有炮兵,1表示第i行沒有炮兵而第i-1行有炮兵,2表示第i行有炮兵
標(biāo)簽:
動(dòng)態(tài)
上傳時(shí)間:
2014-01-26
上傳用戶:努力努力再努力