当前位置: 首页>>代码示例>>C++>>正文


C++ DP函数代码示例

本文整理汇总了C++中DP函数的典型用法代码示例。如果您正苦于以下问题:C++ DP函数的具体用法?C++ DP怎么用?C++ DP使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了DP函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: minDistance

 int minDistance(string word1, string word2) {
     vector<vector<int>> DP(word1.size()+1, vector<int> (word2.size()+1, 0));
     for(int i = 1; i<=word1.size(); i++) {
         DP[i][0] = i;
     }
     for(int j = 1; j <= word2.size(); j++) {
         DP[0][j] = j;
     }
     for(int i = 1; i<=word1.size(); i++) {
         for(int j=1; j<=word2.size(); j++) {
             if(word1[i-1] == word2[j-1]) {
                 DP[i][j] = DP[i-1][j-1];
             }
             else {
                 DP[i][j] = min(min(DP[i-1][j] + 1, DP[i][j-1] + 1), DP[i-1][j-1] + 1);
             }
         }
     }
     return DP[word1.size()][word2.size()];
 }
开发者ID:YuxuanHe,项目名称:Leetcode,代码行数:20,代码来源:Edit+Distance.cpp

示例2: __addip

/* returns 0 on success */
static inline int
__addip(struct ip_set *set, 
	ip_set_ip_t ip, unsigned char *ethernet, ip_set_ip_t *hash_ip)
{
	struct ip_set_macipmap *map =
	    (struct ip_set_macipmap *) set->data;
	struct ip_set_macip *table =
	    (struct ip_set_macip *) map->members;

	if (ip < map->first_ip || ip > map->last_ip)
		return -ERANGE;
	if (test_and_set_bit(IPSET_MACIP_ISSET, 
			     &table[ip - map->first_ip].flags))
		return -EEXIST;

	*hash_ip = ip;
	DP("%u.%u.%u.%u, %u.%u.%u.%u", HIPQUAD(ip), HIPQUAD(*hash_ip));
	memcpy(&table[ip - map->first_ip].ethernet, ethernet, ETH_ALEN);
	return 0;
}
开发者ID:cilynx,项目名称:dd-wrt,代码行数:21,代码来源:ip_set_macipmap.c

示例3: setpool

static int setpool(
	struct sock *sk,
	int optval,
	void *user,
	unsigned int len
) {
	struct ip_pool_request req;

	DP("ip_pool:setpool: optval=%d, user=%p, len=%d\n", optval, user, len);
	if (!capable(CAP_NET_ADMIN))
		return -EPERM;
	if (optval != SO_IP_POOL)
		return -EBADF;
	if (len != sizeof(req))
		return -EINVAL;
	if (copy_from_user(&req, user, sizeof(req)) != 0)
		return -EFAULT;
	printk("obsolete op - upgrade your ippool(8) utility.\n");
	return -EINVAL;
}
开发者ID:JBTech,项目名称:ralink_rt5350,代码行数:20,代码来源:ip_pool.c

示例4: DP

void CSVPHostMountCB::FileOpenL(const TDesC& aName,TUint aMode,TFileOpen anOpen,CFileCB* aFile)
	{
	DP(_L("** (SVPHOSTMNT) CSVPHostMountCB::FileOpenL(%S)"), &aName);
	CSVPHostFileCB& file=(*((CSVPHostFileCB*)aFile));

	TBuf<KMaxPath> name;
	TUint driveNumber = Drive().DriveNumber();
	CanonicalizePathname(aName, driveNumber, name);
	TSVPHostFsFileOpenInfo info(driveNumber, name,aMode,anOpen);
	TInt err = SVP_HOST_FS_DEVICE().FileOpen(info);

	User::LeaveIfError(err);

	file.SetHandle(info.iHandle);
	file.SetSize(info.iSize);
	file.SetAtt(info.iAtt&KEntryAttMaskSupported);
	TTime tempTime=file.Modified();
	fileTimeToTime(info.iModified, tempTime, info.iTimeType);
	file.SetModified(tempTime);
	}
开发者ID:SymbianSource,项目名称:oss.FCL.interim.QEMU,代码行数:20,代码来源:svphostmnt.cpp

示例5: sizeof

wyToast* wyToast::make(const char* text, float duration) {
	// create texture of default toast background
	wyTexture2D* bgTex = wyTexture2D::makeRawPNG((const char*)_toast_bg_png, sizeof(_toast_bg_png) - 2);
	wyNinePatchSprite* bg = wyNinePatchSprite::make(bgTex, wyr(DP(24), DP(24), 1, 1));

	// create label as content
	wyLabel* label = wyLabel::make(text, SP(12), BOLD);
	label->setLineWidth(wyDevice::winWidth * 4 / 5);

	// create toast and set default margin
	wyToast* t = WYNEW wyToast(bg, label, duration);
	t->setMargin(DP(15), DP(20), DP(20), DP(15));
	t->m_useDefaultBg = true;
	return (wyToast*)t->autoRelease();
}
开发者ID:barroque,项目名称:WiEngine,代码行数:15,代码来源:wyToast.cpp

示例6: i2c_select_device

static uchar i2c_select_device (uchar dev_addr, uchar read, int ten_bit)
{
	unsigned int status, data, bits = 7;
	int count = 0;

	DP (puts ("i2c_select_device\n"));

	/* Output slave address */

	if (ten_bit) {
		bits = 10;
	}

	data = (dev_addr << 1);
	/* set the read bit */
	data |= read;
	GT_REG_WRITE (I2C_DATA, data);
	/* assert the address */
	RESET_REG_BITS (I2C_CONTROL, BIT3);

	udelay (I2C_DELAY);

	GT_REG_READ (I2C_STATUS_BAUDE_RATE, &status);
	count = 0;
	while (((status & 0xff) != 0x40) && ((status & 0xff) != 0x18)) {
		udelay (I2C_DELAY);
		if (count > 20) {
			GT_REG_WRITE (I2C_CONTROL, (0x1 << 4));	/*stop */
			return (status);
		}
		GT_REG_READ (I2C_STATUS_BAUDE_RATE, &status);
		count++;
	}

	if (bits == 10) {
		printf ("10 bit I2C addressing not yet implemented\n");
		return (0xff);
	}

	return (0);
}
开发者ID:12019,项目名称:u-boot-2009.07-silvermoon,代码行数:41,代码来源:i2c.c

示例7: i2c_write

/*         anything but zero is failure */
uchar
i2c_write (uchar dev_addr, unsigned int offset, int alen, uchar * data,
	   int len)
{
	uchar status = 0;
	unsigned int i2cFreq = CONFIG_SYS_I2C_SPEED;

	DP (puts ("i2c_write\n"));

	i2c_init (i2cFreq, 0);	/* set the i2c frequency */

	status = i2c_start ();	/* send a start bit */

	if (status) {
#ifdef DEBUG_I2C
		printf ("Transaction start failed: 0x%02x\n", status);
#endif
		return status;
	}

	status = i2c_set_dev_offset (dev_addr, offset, 0, alen);	/* send the slave address + offset */
	if (status) {
#ifdef DEBUG_I2C
		printf ("Failed to set slave address & offset: 0x%02x\n",
			status);
#endif
		return status;
	}


	status = i2c_write_byte (data, len);	/* write the data */
	if (status) {
#ifdef DEBUG_I2C
		printf ("Data not written: 0x%02x\n", status);
#endif
		return status;
	}
	/* issue a stop bit */
	i2c_stop ();
	return 0;
}
开发者ID:12019,项目名称:u-boot-2009.07-silvermoon,代码行数:42,代码来源:i2c.c

示例8: hash_id_cidr

static inline __u32
hash_id_cidr(struct ip_set_nethash *map,
	     ip_set_ip_t ip,
	     unsigned char cidr,
	     ip_set_ip_t *hash_ip)
{
	__u32 id;
	u_int16_t i;
	ip_set_ip_t *elem;

	*hash_ip = pack(ip, cidr);
	
	for (i = 0; i < map->probes; i++) {
		id = jhash_ip(map, i, *hash_ip) % map->hashsize;
	   	DP("hash key: %u", id);
		elem = HARRAY_ELEM(map->members, ip_set_ip_t *, id);
	   	if (*elem == *hash_ip)
			return id;
	}
	return UINT_MAX;
}
开发者ID:inibir,项目名称:daemongroup,代码行数:21,代码来源:ip_set_nethash.c

示例9: adt_parser

/* Add, del, test parser */
static ip_set_ip_t
adt_parser(unsigned cmd, const char *optarg, void *data)
{
	struct ip_set_req_macipmap *mydata =
	    (struct ip_set_req_macipmap *) data;
	char *saved = ipset_strdup(optarg);
	char *ptr, *tmp = saved;

	DP("macipmap: %p %p", optarg, data);

	ptr = strsep(&tmp, ":%");
	parse_ip(ptr, &mydata->ip);

	if (tmp)
		parse_mac(tmp, mydata->ethernet);
	else
		memset(mydata->ethernet, 0, ETH_ALEN);	

	free(saved);
	return 1;	
}
开发者ID:inibir,项目名称:daemongroup,代码行数:22,代码来源:ipset_macipmap.c

示例10: run_com_general

int run_com_general(const char *buffer) {

	int scan_count;

	scan_count = sscanf(buffer, PROC_STRING, PROC_SCANF_LIST);

	if( scan_count != LIST_LEN) {
		printk("eth proc bad format %x != %x\n", scan_count, LIST_LEN );
		return 1;
	}

#ifndef INCLUDE_MULTI_QUEUE
	printk("\n Be carefull eth is compiled without MULTI Q!! \n");
#endif	
	switch(command){
		case COM_SRQ:
			DP(" Port %x: Got SRQ command Q %x and packet type is %x <bpdu/arp/tcp/udp> \n",port,q,packett);
			run_com_srq();
			break;
		case COM_SQ:
			DP(" Port %x: Got SQ command Q %x direction %x <Rx/Tx> mac %2x:%2x:%2x:%2x:%2x:%2x\n",port, q, direct,
				mac[0],  mac[1],  mac[2],  mac[3],  mac[4],  mac[5]);
			run_com_sq();
			break;

#ifdef INCLUDE_MULTI_QUEUE
		case COM_SRP:
			DP(" Port %x: Got SRP command Q %x policy %x <Fixed/WRR> \n",port,q,policy); 
			run_com_srp();
			break;
		case COM_SRQW:
			DP(" Port %x: Got SQRW command Q %x weight %x \n",port,q,weight);
			run_com_srqw();
			break;
		case COM_STP:
			DP("STP cmd - Unsupported: Port %x Q %x policy %x <WRR/FIXED> weight %x\n",port,q,policy,weight); 
			break;
#endif /* INCLUDE_MULTI_QUEUE */

		case COM_STS:
			DP("  Port %x: Got STS command status %x\n",port,status);
			run_com_statis();
			break;
		default:
			printk("eth proc unknown command.\n");
	}
  	return 0;
}
开发者ID:robacklin,项目名称:ts7800,代码行数:48,代码来源:mv_e_proc.c

示例11: minCut

 int minCut(string s) {
     int slen = s.length ();
     if (slen < 2)  return 0;
     dp.resize (slen);
     for (int i=0;i<slen;i++)    dp[i].resize (0);
     
     for (int i=0;i<slen;i++){
         int low = i, high = i+1;
         while (low>=0 && high<slen && s[low]==s[high]){
             dp[high].push_back (low); low--, high++;
         }
         dp[i].push_back (i);
         low = i-1, high = i + 1;
         while (low>=0 && high<slen && s[low]==s[high])
             dp[high].push_back (low),low--, high++;
     }
     f.resize (slen+1);
     fill_n (f.begin(), slen+1, -1);
     f[0] = 0;
     return DP(slen) - 1;
 }
开发者ID:ivanzjj,项目名称:Leetcode,代码行数:21,代码来源:132_Palindrome+Partitioning+II.cpp

示例12: knh_HashMap__k

void knh_HashMap__k(Ctx *ctx, knh_Hash_t *o, OutputStream *w, String *m)
{
	size_t pos = 0, c = 0;
	size_t max = (KNH_HASH_TABLESIZE / o->hashop->size) * DP(o)->tables_size;
	knh_putc(ctx, w, '{');
	while(pos < max) {
		knh_hashentry_t *e = knh_hashentry_at((knh_Hash_t*)o, pos);
		if(e != NULL) {
			if(c > 0) {
				knh_write_delim(ctx,w);
			}
			knh_format(ctx, w, METHODN__k, e->key, KNH_NULL);
			knh_putc(ctx, w, ':');
			knh_putc(ctx, w, ' ');
			knh_format(ctx, w, METHODN__k, e->value, KNH_NULL);
			c++;
		}
		pos++;
	}
	knh_putc(ctx, w, '}');
}
开发者ID:matsuu,项目名称:konoha,代码行数:21,代码来源:hashapi.c

示例13: i2c_probe

/*         anything other than zero is failure, no device */
int i2c_probe (uchar chip)
{

	/* We are just looking for an <ACK> back. */
	/* To see if the device/chip is there */

#ifdef DEBUG_I2C
	unsigned int i2c_status;
#endif
	uchar status = 0;
	unsigned int i2cFreq = CONFIG_SYS_I2C_SPEED;

	DP (puts ("i2c_probe\n"));

	i2c_init (i2cFreq, 0);	/* set the i2c frequency */

	status = i2c_start ();	/* send a start bit */

	if (status) {
#ifdef DEBUG_I2C
		printf ("Transaction start failed: 0x%02x\n", status);
#endif
		return (int) status;
	}

	status = i2c_set_dev_offset (chip, 0, 0, 0);	/* send the slave address + no offset */
	if (status) {
#ifdef DEBUG_I2C
		printf ("Failed to set slave address: 0x%02x\n", status);
#endif
		return (int) status;
	}
#ifdef DEBUG_I2C
	GT_REG_READ (I2C_STATUS_BAUDE_RATE, &i2c_status);
	printf ("address %#x returned %#x\n", chip, i2c_status);
#endif
	/* issue a stop bit */
	i2c_stop ();
	return 0;		/* successful completion */
}
开发者ID:12019,项目名称:u-boot-2009.07-silvermoon,代码行数:41,代码来源:i2c.c

示例14: html_head

// Create a new HTML file with a given filename and title
// The heading, if not given, will be the same as the title
void
html_head(FILE *of, const string fname, const string title, const char *heading)
{
    swill_title(title.c_str());
    if (DP())
        cerr << "Write to " << fname << endl;
    fprintf(of,
            "<!doctype html public \"-//IETF//DTD HTML//EN\">\n"
            "<html>\n"
            "<head>\n"
            "<meta name=\"GENERATOR\" content=\"CScout %s - %s\">\n",
            Version::get_revision().c_str(),
            Version::get_date().c_str());
    fputs(
        "<meta http-equiv=\"Content-Style-Type\" content=\"text/css\">"
        "<style type=\"text/css\" >"
        "<!--\n", of);

    ifstream in;
    string css_fname;
    if (cscout_input_file("style.css", in, css_fname)) {
        int val;
        while ((val = in.get()) != EOF)
            putc(val, of);
    } else
        fputs(
#include "css.c"
            , of);
    fputs(
        "-->"
        "</style>"
        "</head>", of);
    fprintf(of,
            "<title>%s</title>\n"
            "</head>\n"
            "<body>\n"
            "<h1>%s</h1>\n",
            title.c_str(),
            heading ? heading : title.c_str());
}
开发者ID:damorinCan,项目名称:cscout,代码行数:42,代码来源:html.cpp

示例15: i2c_write

int i2c_write(uchar chip, uint addr, int alen, uchar *buffer, int len)
{
	MV_TWSI_SLAVE twsiSlave;
	DP(puts("i2c_write\n"));

	twsiSlave.slaveAddr.type = ADDR7_BIT;
	twsiSlave.slaveAddr.address = chip;
	if(alen != 0){
		twsiSlave.validOffset = MV_TRUE;
		twsiSlave.offset = addr;
		if(alen == 2)
		{
			twsiSlave.moreThen256 = MV_TRUE;
		}
		else
		{
			twsiSlave.moreThen256 = MV_FALSE;
		}
	}
	i2c_init(CONFIG_SYS_I2C_SPEED,0); /* set the i2c frequency */
	return mvTwsiWrite (i2c_current_bus, &twsiSlave, buffer, len);
}
开发者ID:12thmantec,项目名称:u-boot-novena-spl,代码行数:22,代码来源:mv_i2c.c


注:本文中的DP函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。